Changeset 9185 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2015-12-28T01:42:36+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r9184 r9185 22 22 import org.openstreetmap.josm.Main; 23 23 import org.openstreetmap.josm.data.Version; 24 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 24 25 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 25 26 import org.openstreetmap.josm.io.Compression; 27 import org.openstreetmap.josm.io.ProgressInputStream; 28 import org.openstreetmap.josm.io.ProgressOutputStream; 26 29 import org.openstreetmap.josm.io.UTFInputStreamReader; 27 30 … … 61 64 /** 62 65 * Opens the HTTP connection. 63 * @param monitor progress monitor66 * @param progressMonitor progress monitor 64 67 * @return HTTP response 65 68 * @throws IOException if any I/O error occurs 66 69 * @since 9179 67 70 */ 68 public Response connect(ProgressMonitor monitor) throws IOException { 71 public Response connect(ProgressMonitor progressMonitor) throws IOException { 72 if (progressMonitor == null) { 73 progressMonitor = NullProgressMonitor.INSTANCE; 74 } 69 75 final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 70 76 connection.setRequestMethod(requestMethod); … … 89 95 } 90 96 91 // FIXME: use ProgressMonitor 97 progressMonitor.beginTask(tr("Contacting Server..."), 1); 98 progressMonitor.indeterminateSubTask(null); 92 99 93 100 if ("PUT".equals(requestMethod) || "POST".equals(requestMethod) || "DELETE".equals(requestMethod)) { … … 95 102 headers.put("Content-Length", String.valueOf(requestBody.length)); 96 103 connection.setDoOutput(true); 97 try (OutputStream out = new BufferedOutputStream(connection.getOutputStream())) { 104 try (OutputStream out = new BufferedOutputStream( 105 new ProgressOutputStream(connection.getOutputStream(), requestBody.length, progressMonitor))) { 98 106 out.write(requestBody); 99 107 } … … 137 145 } 138 146 } 139 Response response = new Response(connection); 147 Response response = new Response(connection, progressMonitor); 140 148 successfulConnection = true; 141 149 return response; … … 152 160 public static final class Response { 153 161 private final HttpURLConnection connection; 162 private final ProgressMonitor monitor; 154 163 private final int responseCode; 155 164 private final String responseMessage; … … 157 166 private boolean uncompressAccordingToContentDisposition; 158 167 159 private Response(HttpURLConnection connection) throws IOException { 168 private Response(HttpURLConnection connection, ProgressMonitor monitor) throws IOException { 160 169 CheckParameterUtil.ensureParameterNotNull(connection, "connection"); 170 CheckParameterUtil.ensureParameterNotNull(monitor, "monitor"); 161 171 this.connection = connection; 172 this.monitor = monitor; 162 173 this.responseCode = connection.getResponseCode(); 163 174 this.responseMessage = connection.getResponseMessage(); … … 227 238 in = connection.getErrorStream(); 228 239 } 240 in = new ProgressInputStream(in, getContentLength(), monitor); 229 241 in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in; 230 242 Compression compression = Compression.NONE;
Note:
See TracChangeset
for help on using the changeset viewer.