1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.spdy;
17
18
19
20
21
22 public class SpdyStreamStatus implements Comparable<SpdyStreamStatus> {
23
24
25
26
27 public static final SpdyStreamStatus PROTOCOL_ERROR =
28 new SpdyStreamStatus(1, "PROTOCOL_ERROR");
29
30
31
32
33 public static final SpdyStreamStatus INVALID_STREAM =
34 new SpdyStreamStatus(2, "INVALID_STREAM");
35
36
37
38
39 public static final SpdyStreamStatus REFUSED_STREAM =
40 new SpdyStreamStatus(3, "REFUSED_STREAM");
41
42
43
44
45 public static final SpdyStreamStatus UNSUPPORTED_VERSION =
46 new SpdyStreamStatus(4, "UNSUPPORTED_VERSION");
47
48
49
50
51 public static final SpdyStreamStatus CANCEL =
52 new SpdyStreamStatus(5, "CANCEL");
53
54
55
56
57 public static final SpdyStreamStatus INTERNAL_ERROR =
58 new SpdyStreamStatus(6, "INTERNAL_ERROR");
59
60
61
62
63 public static final SpdyStreamStatus FLOW_CONTROL_ERROR =
64 new SpdyStreamStatus(7, "FLOW_CONTROL_ERROR");
65
66
67
68
69 public static final SpdyStreamStatus STREAM_IN_USE =
70 new SpdyStreamStatus(8, "STREAM_IN_USE");
71
72
73
74
75 public static final SpdyStreamStatus STREAM_ALREADY_CLOSED =
76 new SpdyStreamStatus(9, "STREAM_ALREADY_CLOSED");
77
78
79
80
81 public static final SpdyStreamStatus INVALID_CREDENTIALS =
82 new SpdyStreamStatus(10, "INVALID_CREDENTIALS");
83
84
85
86
87 public static final SpdyStreamStatus FRAME_TOO_LARGE =
88 new SpdyStreamStatus(11, "FRAME_TOO_LARGE");
89
90
91
92
93
94
95 public static SpdyStreamStatus valueOf(int code) {
96 if (code == 0) {
97 throw new IllegalArgumentException(
98 "0 is not a valid status code for a RST_STREAM");
99 }
100
101 switch (code) {
102 case 1:
103 return PROTOCOL_ERROR;
104 case 2:
105 return INVALID_STREAM;
106 case 3:
107 return REFUSED_STREAM;
108 case 4:
109 return UNSUPPORTED_VERSION;
110 case 5:
111 return CANCEL;
112 case 6:
113 return INTERNAL_ERROR;
114 case 7:
115 return FLOW_CONTROL_ERROR;
116 case 8:
117 return STREAM_IN_USE;
118 case 9:
119 return STREAM_ALREADY_CLOSED;
120 case 10:
121 return INVALID_CREDENTIALS;
122 case 11:
123 return FRAME_TOO_LARGE;
124 }
125
126 return new SpdyStreamStatus(code, "UNKNOWN (" + code + ')');
127 }
128
129 private final int code;
130
131 private final String statusPhrase;
132
133
134
135
136
137 public SpdyStreamStatus(int code, String statusPhrase) {
138 if (code == 0) {
139 throw new IllegalArgumentException(
140 "0 is not a valid status code for a RST_STREAM");
141 }
142
143 if (statusPhrase == null) {
144 throw new NullPointerException("statusPhrase");
145 }
146
147 this.code = code;
148 this.statusPhrase = statusPhrase;
149 }
150
151
152
153
154 public int getCode() {
155 return code;
156 }
157
158
159
160
161 public String getStatusPhrase() {
162 return statusPhrase;
163 }
164
165 @Override
166 public int hashCode() {
167 return getCode();
168 }
169
170 @Override
171 public boolean equals(Object o) {
172 if (!(o instanceof SpdyStreamStatus)) {
173 return false;
174 }
175
176 return getCode() == ((SpdyStreamStatus) o).getCode();
177 }
178
179 @Override
180 public String toString() {
181 return getStatusPhrase();
182 }
183
184 public int compareTo(SpdyStreamStatus o) {
185 return getCode() - o.getCode();
186 }
187 }