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