View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.spdy.api;
20  
21  /**
22   * <p>A container for SYN_REPLY frames metadata and headers.</p>
23   */
24  public class ReplyInfo
25  {
26      /**
27       * <p>Flag that indicates that this {@link ReplyInfo} is the last frame in the stream.</p>
28       *
29       * @see #isClose()
30       * @see #getFlags()
31       */
32      public static final byte FLAG_CLOSE = 1;
33  
34      private final Headers headers;
35      private final boolean close;
36  
37      /**
38       * <p>Creates a new {@link ReplyInfo} instance with empty headers and the given close flag.</p>
39       *
40       * @param close the value of the close flag
41       */
42      public ReplyInfo(boolean close)
43      {
44          this(new Headers(), close);
45      }
46  
47      /**
48       * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag.</p>
49       *
50       * @param headers the {@link Headers}
51       * @param close the value of the close flag
52       */
53      public ReplyInfo(Headers headers, boolean close)
54      {
55          this.headers = headers;
56          this.close = close;
57      }
58  
59      /**
60       * @return the {@link Headers}
61       */
62      public Headers getHeaders()
63      {
64          return headers;
65      }
66  
67      /**
68       * @return the value of the close flag
69       */
70      public boolean isClose()
71      {
72          return close;
73      }
74  
75      /**
76       * @return the close and reset compression flags as integer
77       * @see #FLAG_CLOSE
78       */
79      public byte getFlags()
80      {
81          return isClose() ? FLAG_CLOSE : 0;
82      }
83  
84      @Override
85      public String toString()
86      {
87          return String.format("REPLY close=%b %s", close, headers);
88      }
89  }