- Timestamp:
- 2016-05-30T09:24:08+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/ProgressOutputStream.java
r9669 r10302 19 19 private final StreamProgressUpdater updater; 20 20 private final OutputStream out; 21 private final boolean finishOnClose; 21 22 22 23 /** … … 26 27 * @param size the total size which will be sent 27 28 * @param progressMonitor the monitor to report to 29 * @param finishOnClose whether to call {@link ProgressMonitor#finishTask} when this stream is closed 30 * @since 10302 28 31 */ 29 public ProgressOutputStream(OutputStream out, long size, ProgressMonitor progressMonitor) { 30 if (progressMonitor == null) { 31 progressMonitor = NullProgressMonitor.INSTANCE; 32 } 33 this.updater = new StreamProgressUpdater(size, progressMonitor, tr("Uploading data ...")); 32 public ProgressOutputStream(OutputStream out, long size, ProgressMonitor progressMonitor, boolean finishOnClose) { 33 this.updater = new StreamProgressUpdater(size, 34 progressMonitor != null ? progressMonitor : NullProgressMonitor.INSTANCE, tr("Uploading data ...")); 34 35 this.out = out; 36 this.finishOnClose = finishOnClose; 35 37 } 36 38 … … 52 54 out.close(); 53 55 } finally { 54 updater.finishTask(); 56 if (finishOnClose) { 57 updater.finishTask(); 58 } 55 59 } 56 60 } -
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r10300 r10302 52 52 private HttpURLConnection connection; // to allow disconnecting before `response` is set 53 53 private Response response; 54 private boolean finishOnCloseOutput = true; 54 55 55 56 static { … … 111 112 connection.setDoOutput(true); 112 113 try (OutputStream out = new BufferedOutputStream( 113 new ProgressOutputStream(connection.getOutputStream(), requestBody.length, progressMonitor))) { 114 new ProgressOutputStream(connection.getOutputStream(), requestBody.length, progressMonitor, finishOnCloseOutput))) { 114 115 out.write(requestBody); 115 116 } … … 598 599 } 599 600 601 /** 602 * Sets whether the progress monitor task will be finished when the output stream is closed. This is {@code true} by default. 603 * @param finishOnCloseOutput whether the progress monitor task will be finished when the output stream is closed 604 * @return {@code this} 605 * @since 10302 606 */ 607 public HttpClient setFinishOnCloseOutput(boolean finishOnCloseOutput) { 608 this.finishOnCloseOutput = finishOnCloseOutput; 609 return this; 610 } 611 600 612 private static boolean isRedirect(final int statusCode) { 601 613 switch (statusCode) { -
trunk/test/config/functional-josm.home
- Property svn:ignore
-
old new 3 3 preferences.xml_tmp 4 4 preferences.xml 5 validator
-
- Property svn:ignore
-
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r9807 r10302 101 101 .setHeader("Content-Type", "text/plain") 102 102 .setRequestBody(text.getBytes(StandardCharsets.UTF_8)) 103 .setFinishOnCloseOutput(false) // to fix #12583, not sure if it's the best way to do it 103 104 .connect(progress); 104 105 assertThat(response.getResponseCode(), is(200)); … … 114 115 .setHeader("Content-Type", "text/plain") 115 116 .setRequestBody("".getBytes(StandardCharsets.UTF_8)) 117 .setFinishOnCloseOutput(false) // to fix #12583, not sure if it's the best way to do it 116 118 .connect(progress); 117 119 assertThat(response.getResponseCode(), is(200));
Note:
See TracChangeset
for help on using the changeset viewer.