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