1 //
2 // ========================================================================
3 // Copyright (c) 1995-2012 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 import org.eclipse.jetty.util.Fields;
22
23 /**
24 * <p>A container for SYN_REPLY frames metadata and headers.</p>
25 */
26 public class ReplyInfo
27 {
28 /**
29 * <p>Flag that indicates that this {@link ReplyInfo} is the last frame in the stream.</p>
30 *
31 * @see #isClose()
32 * @see #getFlags()
33 */
34 public static final byte FLAG_CLOSE = 1;
35
36 private final Fields headers;
37 private final boolean close;
38
39 /**
40 * <p>Creates a new {@link ReplyInfo} instance with empty headers and the given close flag.</p>
41 *
42 * @param close the value of the close flag
43 */
44 public ReplyInfo(boolean close)
45 {
46 this(new Fields(), close);
47 }
48
49 /**
50 * <p>Creates a {@link ReplyInfo} instance with the given headers and the given close flag.</p>
51 *
52 * @param headers the {@link Fields}
53 * @param close the value of the close flag
54 */
55 public ReplyInfo(Fields headers, boolean close)
56 {
57 this.headers = headers;
58 this.close = close;
59 }
60
61 /**
62 * @return the {@link Fields}
63 */
64 public Fields getHeaders()
65 {
66 return headers;
67 }
68
69 /**
70 * @return the value of the close flag
71 */
72 public boolean isClose()
73 {
74 return close;
75 }
76
77 /**
78 * @return the close and reset compression flags as integer
79 * @see #FLAG_CLOSE
80 */
81 public byte getFlags()
82 {
83 return isClose() ? FLAG_CLOSE : 0;
84 }
85
86 @Override
87 public String toString()
88 {
89 return String.format("REPLY close=%b %s", close, headers);
90 }
91 }