LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 * Copyright (c) 2011 Google Inc. | 2 * Copyright (c) 2011 Google Inc. |
3 * | 3 * |
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not u
se this file except |
5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
6 * | 6 * |
7 * http://www.apache.org/licenses/LICENSE-2.0 | 7 * http://www.apache.org/licenses/LICENSE-2.0 |
8 * | 8 * |
9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // Add specified headers (if any) to the headers in the request. | 151 // Add specified headers (if any) to the headers in the request. |
152 request.getHeaders().putAll(getRequestHeaders()); | 152 request.getHeaders().putAll(getRequestHeaders()); |
153 return request; | 153 return request; |
154 } | 154 } |
155 | 155 |
156 /** | 156 /** |
157 * Sends the request to the server and returns the raw {@link HttpResponse}. S
ubclasses may | 157 * Sends the request to the server and returns the raw {@link HttpResponse}. S
ubclasses may |
158 * override if specific behavior is required. | 158 * override if specific behavior is required. |
159 * | 159 * |
160 * <p> | 160 * <p> |
161 * Callers are responsible for closing the response's content input stream by
calling | 161 * Callers are responsible for disconnecting the HTTP response by calling |
162 * {@link HttpResponse#ignore}. | 162 * {@link HttpResponse#disconnect}. Example usage: |
163 * </p> | 163 * </p> |
| 164 * |
| 165 * <pre> |
| 166 HttpResponse response = jsonHttpRequest.executeUnparsed(); |
| 167 try { |
| 168 // process response.. |
| 169 } finally { |
| 170 response.disconnect(); |
| 171 } |
| 172 * </pre> |
164 * | 173 * |
165 * @return the {@link HttpResponse} | 174 * @return the {@link HttpResponse} |
166 * @throws IOException if the request fails | 175 * @throws IOException if the request fails |
167 */ | 176 */ |
168 public HttpResponse executeUnparsed() throws IOException { | 177 public HttpResponse executeUnparsed() throws IOException { |
169 HttpRequest request = buildHttpRequest(); | 178 HttpRequest request = buildHttpRequest(); |
170 HttpResponse response = client.executeUnparsed(request); | 179 HttpResponse response = client.executeUnparsed(request); |
171 lastResponseHeaders = response.getHeaders(); | 180 lastResponseHeaders = response.getHeaders(); |
172 return response; | 181 return response; |
173 } | 182 } |
174 | 183 |
175 /** | 184 /** |
176 * Sends the request to the server and returns the content input stream of {@l
ink HttpResponse}. | 185 * Sends the request to the server and returns the content input stream of {@l
ink HttpResponse}. |
177 * Subclasses may override if specific behavior is required. | 186 * Subclasses may override if specific behavior is required. |
178 * | 187 * |
179 * <p> | 188 * <p> |
180 * Callers are responsible for closing the input stream. | 189 * Callers are responsible for closing the input stream after it is processed.
Example sample: |
181 * </p> | 190 * </p> |
| 191 * |
| 192 * <pre> |
| 193 InputStream is = request.executeAsInputStream(); |
| 194 try { |
| 195 // Process input stream.. |
| 196 } finally { |
| 197 is.close(); |
| 198 } |
| 199 * </pre> |
182 * | 200 * |
183 * @return input stream of the response content | 201 * @return input stream of the response content |
184 * @throws IOException if the request fails | 202 * @throws IOException if the request fails |
185 * @since 1.8 | 203 * @since 1.8 |
186 */ | 204 */ |
187 public InputStream executeAsInputStream() throws IOException { | 205 public InputStream executeAsInputStream() throws IOException { |
188 HttpResponse response = executeUnparsed(); | 206 HttpResponse response = executeUnparsed(); |
189 return response.getContent(); | 207 return response.getContent(); |
190 } | 208 } |
191 | 209 |
192 /** | 210 /** |
193 * Sends the request to the server and writes the content input stream of {@li
nk HttpResponse} | 211 * Sends the request to the server and writes the content input stream of {@li
nk HttpResponse} |
194 * into the given destination output stream. | 212 * into the given destination output stream. |
195 * | 213 * |
196 * <p> | 214 * <p> |
197 * This method closes the content of the HTTP response from {@link HttpRespons
e#getContent()}. | 215 * This method closes the content of the HTTP response from {@link HttpRespons
e#getContent()}. |
198 * </p> | 216 * </p> |
199 * | 217 * |
200 * @param outputStream destination output stream | 218 * @param outputStream destination output stream |
201 * @throws IOException I/O exception | 219 * @throws IOException I/O exception |
202 * @since 1.9 | 220 * @since 1.9 |
203 */ | 221 */ |
204 public void download(OutputStream outputStream) throws IOException { | 222 public void download(OutputStream outputStream) throws IOException { |
205 HttpResponse response = executeUnparsed(); | 223 HttpResponse response = executeUnparsed(); |
206 response.download(outputStream); | 224 response.download(outputStream); |
207 } | 225 } |
208 } | 226 } |
LEFT | RIGHT |