Changeset 9178 in josm
- Timestamp:
- 2015-12-27T16:02:24+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r9177 r9178 9 9 import java.io.InputStream; 10 10 import java.io.OutputStream; 11 import java.net.HttpRetryException; 11 12 import java.net.HttpURLConnection; 12 13 import java.net.URL; … … 36 37 private byte[] requestBody; 37 38 private long ifModifiedSince; 39 private long contentLength; 38 40 private final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); 39 41 private int maxRedirects = Main.pref.getInteger("socket.maxredirects", 5); … … 61 63 if (ifModifiedSince > 0) { 62 64 connection.setIfModifiedSince(ifModifiedSince); 65 } 66 if (contentLength > 0) { 67 connection.setFixedLengthStreamingMode(contentLength); 63 68 } 64 69 connection.setUseCaches(useCache); … … 158 163 * {@code Content-Disposition} 159 164 * @return {@code this} 165 * @since 9172 160 166 */ 161 167 public Response uncompressAccordingToContentDisposition(boolean uncompressAccordingToContentDisposition) { … … 168 174 * @return the URL 169 175 * @see HttpURLConnection#getURL() 176 * @since 9172 170 177 */ 171 178 public URL getURL() { … … 177 184 * @return the HTTP request method 178 185 * @see HttpURLConnection#getRequestMethod() 186 * @since 9172 179 187 */ 180 188 public String getRequestMethod() { … … 260 268 * 261 269 * @see HttpURLConnection#getResponseMessage() 270 * @since 9172 262 271 */ 263 272 public String getResponseMessage() { … … 294 303 * @return the value of the named header field, or {@code null} if there is no such field in the header 295 304 * @see HttpURLConnection#getHeaderField(String) 305 * @since 9172 296 306 */ 297 307 public String getHeaderField(String name) { … … 304 314 * @return unmodifiable List of Strings that represents the corresponding field values 305 315 * @see HttpURLConnection#getHeaderFields() 316 * @since 9172 306 317 */ 307 318 public List<String> getHeaderFields(String name) { … … 353 364 * @see #create(URL) 354 365 * @see #create(URL, String) 366 * @since 9172 355 367 */ 356 368 public URL getURL() { … … 362 374 * @return the HTTP request method 363 375 * @see #create(URL, String) 376 * @since 9172 364 377 */ 365 378 public String getRequestMethod() { … … 371 384 * @param header HTTP header name 372 385 * @return HTTP header value 386 * @since 9172 373 387 */ 374 388 public String getRequestHeader(String header) { … … 420 434 * @param readTimeout an {@code int} that specifies the read timeout value in milliseconds 421 435 * @return {@code this} 422 * @see HttpURLConnection#setReadTimeout(int) (int)436 * @see HttpURLConnection#setReadTimeout(int) 423 437 */ 424 438 public HttpClient setReadTimeout(int readTimeout) { 425 439 this.readTimeout = readTimeout; 440 return this; 441 } 442 443 /** 444 * This method is used to enable streaming of a HTTP request body without internal buffering, 445 * when the content length is known in advance. 446 * <p> 447 * An exception will be thrown if the application attempts to write more data than the indicated content-length, 448 * or if the application closes the OutputStream before writing the indicated amount. 449 * <p> 450 * When output streaming is enabled, authentication and redirection cannot be handled automatically. 451 * A {@linkplain HttpRetryException} will be thrown when reading the response if authentication or redirection 452 * are required. This exception can be queried for the details of the error. 453 * 454 * @param contentLength The number of bytes which will be written to the OutputStream 455 * @return {@code this} 456 * @see HttpURLConnection#setFixedLengthStreamingMode(long) 457 * @since 9178 458 */ 459 public HttpClient setFixedLengthStreamingMode(long contentLength) { 460 this.contentLength = contentLength; 426 461 return this; 427 462 } … … 500 535 * @param reasonForRequest Reason to show 501 536 * @return {@code this} 537 * @since 9172 502 538 */ 503 539 public HttpClient setReasonForRequest(String reasonForRequest) {
Note:
See TracChangeset
for help on using the changeset viewer.