Ignore:
Timestamp:
2015-12-28T01:42:36+01:00 (4 years ago)
Author:
simon04
Message:

see #12231 - HttpClient now reports status to ProgressMonitor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r9184 r9185  
    2222import org.openstreetmap.josm.Main;
    2323import org.openstreetmap.josm.data.Version;
     24import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2425import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2526import org.openstreetmap.josm.io.Compression;
     27import org.openstreetmap.josm.io.ProgressInputStream;
     28import org.openstreetmap.josm.io.ProgressOutputStream;
    2629import org.openstreetmap.josm.io.UTFInputStreamReader;
    2730
     
    6164    /**
    6265     * Opens the HTTP connection.
    63      * @param monitor progress monitor
     66     * @param progressMonitor progress monitor
    6467     * @return HTTP response
    6568     * @throws IOException if any I/O error occurs
    6669     * @since 9179
    6770     */
    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        }
    6975        final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    7076        connection.setRequestMethod(requestMethod);
     
    8995        }
    9096
    91         // FIXME: use ProgressMonitor
     97        progressMonitor.beginTask(tr("Contacting Server..."), 1);
     98        progressMonitor.indeterminateSubTask(null);
    9299
    93100        if ("PUT".equals(requestMethod) || "POST".equals(requestMethod) || "DELETE".equals(requestMethod)) {
     
    95102            headers.put("Content-Length", String.valueOf(requestBody.length));
    96103            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))) {
    98106                out.write(requestBody);
    99107            }
     
    137145                }
    138146            }
    139             Response response = new Response(connection);
     147            Response response = new Response(connection, progressMonitor);
    140148            successfulConnection = true;
    141149            return response;
     
    152160    public static final class Response {
    153161        private final HttpURLConnection connection;
     162        private final ProgressMonitor monitor;
    154163        private final int responseCode;
    155164        private final String responseMessage;
     
    157166        private boolean uncompressAccordingToContentDisposition;
    158167
    159         private Response(HttpURLConnection connection) throws IOException {
     168        private Response(HttpURLConnection connection, ProgressMonitor monitor) throws IOException {
    160169            CheckParameterUtil.ensureParameterNotNull(connection, "connection");
     170            CheckParameterUtil.ensureParameterNotNull(monitor, "monitor");
    161171            this.connection = connection;
     172            this.monitor = monitor;
    162173            this.responseCode = connection.getResponseCode();
    163174            this.responseMessage = connection.getResponseMessage();
     
    227238                in = connection.getErrorStream();
    228239            }
     240            in = new ProgressInputStream(in, getContentLength(), monitor);
    229241            in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in;
    230242            Compression compression = Compression.NONE;
Note: See TracChangeset for help on using the changeset viewer.