View Javadoc

1   /*
2    * Copyright 2012 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 SpdyHeaderBlock} implementation.
26   */
27  public class DefaultSpdyHeaderBlock implements SpdyHeaderBlock {
28  
29      private boolean invalid;
30      private final SpdyHeaders headers = new SpdyHeaders();
31  
32      /**
33       * Creates a new instance.
34       */
35      protected DefaultSpdyHeaderBlock() {
36      }
37  
38      public boolean isInvalid() {
39          return invalid;
40      }
41  
42      public void setInvalid() {
43          invalid = true;
44      }
45  
46      public void addHeader(final String name, final Object value) {
47          headers.addHeader(name, value);
48      }
49  
50      public void setHeader(final String name, final Object value) {
51          headers.setHeader(name, value);
52      }
53  
54      public void setHeader(final String name, final Iterable<?> values) {
55          headers.setHeader(name, values);
56      }
57  
58      public void removeHeader(final String name) {
59          headers.removeHeader(name);
60      }
61  
62      public void clearHeaders() {
63          headers.clearHeaders();
64      }
65  
66      public String getHeader(final String name) {
67          return headers.getHeader(name);
68      }
69  
70      public List<String> getHeaders(final String name) {
71          return headers.getHeaders(name);
72      }
73  
74      public List<Map.Entry<String, String>> getHeaders() {
75          return headers.getHeaders();
76      }
77  
78      public boolean containsHeader(final String name) {
79          return headers.containsHeader(name);
80      }
81  
82      public Set<String> getHeaderNames() {
83          return headers.getHeaderNames();
84      }
85  
86      protected void appendHeaders(StringBuilder buf) {
87          for (Map.Entry<String, String> e: getHeaders()) {
88              buf.append("    ");
89              buf.append(e.getKey());
90              buf.append(": ");
91              buf.append(e.getValue());
92              buf.append(StringUtil.NEWLINE);
93          }
94      }
95  }