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 SYN_REPLY frames metadata and headers.</p>
21   */
22  public class ReplyInfo
23  {
24      /**
25       * <p>Flag that indicates that this {@link ReplyInfo} 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      private final Headers headers;
33      private final boolean close;
34  
35      /**
36       * <p>Creates a new {@link ReplyInfo} instance with empty headers and the given close flag.</p>
37       *
38       * @param close the value of the close flag
39       */
40      public ReplyInfo(boolean close)
41      {
42          this(new Headers(), close);
43      }
44  
45      /**
46       * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag.</p>
47       *
48       * @param headers the {@link Headers}
49       * @param close the value of the close flag
50       */
51      public ReplyInfo(Headers headers, boolean close)
52      {
53          this.headers = headers;
54          this.close = close;
55      }
56  
57      /**
58       * @return the {@link Headers}
59       */
60      public Headers getHeaders()
61      {
62          return headers;
63      }
64  
65      /**
66       * @return the value of the close flag
67       */
68      public boolean isClose()
69      {
70          return close;
71      }
72  
73      /**
74       * @return the close and reset compression flags as integer
75       * @see #FLAG_CLOSE
76       */
77      public byte getFlags()
78      {
79          return isClose() ? FLAG_CLOSE : 0;
80      }
81  
82      @Override
83      public String toString()
84      {
85          return String.format("REPLY close=%b %s", close, headers);
86      }
87  }