查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package org.jboss.netty.handler.codec.spdy;
17  
18  import java.util.List;
19  import java.util.Map;
20  import java.util.Set;
21  
22  import org.jboss.netty.util.internal.StringUtil;
23  
24  /**
25   * The default {@link SpdyHeadersFrame} implementation.
26   */
27  public class DefaultSpdyHeadersFrame extends DefaultSpdyStreamFrame
28          implements SpdyHeadersFrame {
29  
30      private boolean invalid;
31      private boolean truncated;
32      private final SpdyHeaders headers = new DefaultSpdyHeaders();
33  
34      /**
35       * Creates a new instance.
36       *
37       * @param streamId the Stream-ID of this frame
38       */
39      public DefaultSpdyHeadersFrame(int streamId) {
40          super(streamId);
41      }
42  
43      public boolean isInvalid() {
44          return invalid;
45      }
46  
47      public void setInvalid() {
48          invalid = true;
49      }
50  
51      public boolean isTruncated() {
52          return truncated;
53      }
54  
55      public void setTruncated() {
56          truncated = true;
57      }
58  
59      public SpdyHeaders headers() {
60          return headers;
61      }
62  
63      @Override
64      public String toString() {
65          StringBuilder buf = new StringBuilder();
66          buf.append(getClass().getSimpleName());
67          buf.append("(last: ");
68          buf.append(isLast());
69          buf.append(')');
70          buf.append(StringUtil.NEWLINE);
71          buf.append("--> Stream-ID = ");
72          buf.append(getStreamId());
73          buf.append(StringUtil.NEWLINE);
74          buf.append("--> Headers:");
75          buf.append(StringUtil.NEWLINE);
76          appendHeaders(buf);
77  
78          // Remove the last newline.
79          buf.setLength(buf.length() - StringUtil.NEWLINE.length());
80          return buf.toString();
81      }
82  
83      protected void appendHeaders(StringBuilder buf) {
84          for (Map.Entry<String, String> e: headers()) {
85              buf.append("    ");
86              buf.append(e.getKey());
87              buf.append(": ");
88              buf.append(e.getValue());
89              buf.append(StringUtil.NEWLINE);
90          }
91      }
92  }