View Javadoc

1   /*
2    * Copyright (c) 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * 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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.eclipse.jetty.spdy.api;
18  
19  /**
20   * <p>A container for HEADERS frame metadata and headers.</p>
21   */
22  public class HeadersInfo
23  {
24      /**
25       * <p>Flag that indicates that this {@link HeadersInfo} is the last frame in the stream.</p>
26       *
27       * @see #isClose()
28       * @see #getFlags()
29       */
30      public static final byte FLAG_CLOSE = 1;
31      /**
32       * <p>Flag that indicates that the compression of the stream must be reset.</p>
33       *
34       * @see #isResetCompression()
35       * @see #getFlags()
36       */
37      public static final byte FLAG_RESET_COMPRESSION = 2;
38  
39      private final boolean close;
40      private final boolean resetCompression;
41      private final Headers headers;
42  
43      /**
44       * <p>Creates a new {@link HeadersInfo} instance with the given headers,
45       * the given close flag and no reset compression flag</p>
46       *
47       * @param headers the {@link Headers}
48       * @param close the value of the close flag
49       */
50      public HeadersInfo(Headers headers, boolean close)
51      {
52          this(headers, close, false);
53      }
54  
55      /**
56       * <p>Creates a new {@link HeadersInfo} instance with the given headers,
57       * the given close flag and the given reset compression flag</p>
58       *
59       * @param headers the {@link Headers}
60       * @param close the value of the close flag
61       * @param resetCompression the value of the reset compression flag
62       */
63      public HeadersInfo(Headers headers, boolean close, boolean resetCompression)
64      {
65          this.headers = headers;
66          this.close = close;
67          this.resetCompression = resetCompression;
68      }
69  
70      /**
71       * @return the value of the close flag
72       */
73      public boolean isClose()
74      {
75          return close;
76      }
77  
78      /**
79       * @return the value of the reset compression flag
80       */
81      public boolean isResetCompression()
82      {
83          return resetCompression;
84      }
85  
86      /**
87       * @return the {@link Headers}
88       */
89      public Headers getHeaders()
90      {
91          return headers;
92      }
93  
94      /**
95       * @return the close and reset compression flags as integer
96       * @see #FLAG_CLOSE
97       * @see #FLAG_RESET_COMPRESSION
98       */
99      public byte getFlags()
100     {
101         byte flags = isClose() ? FLAG_CLOSE : 0;
102         flags += isResetCompression() ? FLAG_RESET_COMPRESSION : 0;
103         return flags;
104     }
105 
106     @Override
107     public String toString()
108     {
109         return String.format("HEADER close=%b %s", close, headers);
110     }
111 }