38 |
|
|
39 |
package gnu.java.net.protocol.http; |
package gnu.java.net.protocol.http; |
40 |
|
|
41 |
|
import java.io.InputStream; |
42 |
import java.util.Date; |
import java.util.Date; |
43 |
|
|
44 |
/** |
/** |
65 |
protected final int code; |
protected final int code; |
66 |
|
|
67 |
/** |
/** |
|
* The class of the response. This is the most significant digit of the |
|
|
* status code. |
|
|
* <dl> |
|
|
* <dt><code>1xx</code></dt> <dd>Informational response</dd> |
|
|
* <dt><code>2xx</code></dt> <dd>Success</dd> |
|
|
* <dt><code>3xx</code></dt> <dd>Redirection</dd> |
|
|
* <dt><code>4xx</code></dt> <dd>Client error</dd> |
|
|
* <dt><code>5xx</code></dt> <dd>Server error</dd> |
|
|
* </dl> |
|
|
*/ |
|
|
protected final int codeClass; |
|
|
|
|
|
/** |
|
68 |
* Human-readable text of the response. |
* Human-readable text of the response. |
69 |
*/ |
*/ |
70 |
protected final String message; |
protected final String message; |
75 |
protected final Headers headers; |
protected final Headers headers; |
76 |
|
|
77 |
/** |
/** |
78 |
|
* An InputStream that returns the body of the response. |
79 |
|
*/ |
80 |
|
protected final InputStream body; |
81 |
|
|
82 |
|
/** |
83 |
* Constructs a new response with the specified parameters. |
* Constructs a new response with the specified parameters. |
84 |
*/ |
*/ |
85 |
protected Response(int majorVersion, int minorVersion, int code, |
protected Response(int majorVersion, int minorVersion, int code, |
86 |
int codeClass, String message, |
String message, Headers headers, InputStream body) |
|
Headers headers) |
|
87 |
{ |
{ |
88 |
this.majorVersion = majorVersion; |
this.majorVersion = majorVersion; |
89 |
this.minorVersion = minorVersion; |
this.minorVersion = minorVersion; |
90 |
this.code = code; |
this.code = code; |
|
this.codeClass = codeClass; |
|
91 |
this.message = message; |
this.message = message; |
92 |
this.headers = headers; |
this.headers = headers; |
93 |
|
this.body = body; |
94 |
} |
} |
95 |
|
|
96 |
/** |
/** |
121 |
} |
} |
122 |
|
|
123 |
/** |
/** |
124 |
* Returns the class of the response. |
* Returns the class of the response. This is the most significant |
125 |
* @see #codeClass |
* digit of the status code. |
126 |
|
* <dl> |
127 |
|
* <dt><code>1xx</code></dt> <dd>Informational response</dd> |
128 |
|
* <dt><code>2xx</code></dt> <dd>Success</dd> |
129 |
|
* <dt><code>3xx</code></dt> <dd>Redirection</dd> |
130 |
|
* <dt><code>4xx</code></dt> <dd>Client error</dd> |
131 |
|
* <dt><code>5xx</code></dt> <dd>Server error</dd> |
132 |
|
* </dl> |
133 |
*/ |
*/ |
134 |
public int getCodeClass() |
public int getCodeClass() |
135 |
{ |
{ |
136 |
return codeClass; |
return code / 100; |
137 |
} |
} |
138 |
|
|
139 |
/** |
/** |
172 |
} |
} |
173 |
|
|
174 |
/** |
/** |
175 |
|
* Returns the header value for the specified name as a long. |
176 |
|
* @param name the header name |
177 |
|
*/ |
178 |
|
public long getLongHeader(String name) |
179 |
|
{ |
180 |
|
return headers.getLongValue(name); |
181 |
|
} |
182 |
|
|
183 |
|
/** |
184 |
* Returns the header value for the specified name as a date. |
* Returns the header value for the specified name as a date. |
185 |
* @param name the header name |
* @param name the header name |
186 |
*/ |
*/ |
189 |
return headers.getDateValue(name); |
return headers.getDateValue(name); |
190 |
} |
} |
191 |
|
|
192 |
|
/** |
193 |
|
* Returns an InputStream that returns the body of the response. |
194 |
|
* |
195 |
|
* @return the body of the response |
196 |
|
*/ |
197 |
|
public InputStream getBody() |
198 |
|
{ |
199 |
|
return body; |
200 |
|
} |
201 |
} |
} |
202 |
|
|