Ignore:
Timestamp:
2015-12-26T23:42:00+01:00 (9 years ago)
Author:
simon04
Message:

see #12231 - Use HttpClient instead of some Utils.openHttpConnection usages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadFileTask.java

    r9059 r9171  
    1111import java.io.InputStream;
    1212import java.io.OutputStream;
    13 import java.net.HttpURLConnection;
    1413import java.net.MalformedURLException;
    1514import java.net.URL;
     
    2221import org.openstreetmap.josm.gui.PleaseWaitDialog;
    2322import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    24 import org.openstreetmap.josm.tools.Utils;
     23import org.openstreetmap.josm.tools.HttpClient;
    2524import org.xml.sax.SAXException;
    2625
     
    6867
    6968    private boolean canceled;
    70     private HttpURLConnection downloadConnection;
     69    private HttpClient.Response downloadConnection;
    7170
    7271    private synchronized void closeConnectionIfNeeded() {
     
    10099
    101100            URL url = new URL(address);
    102             int size;
     101            long size;
    103102            synchronized (this) {
    104                 downloadConnection = Utils.openHttpConnection(url);
    105                 downloadConnection.setRequestProperty("Cache-Control", "no-cache");
    106                 downloadConnection.connect();
     103                downloadConnection = HttpClient.create(url).useCache(false).connect();
    107104                size = downloadConnection.getContentLength();
    108105            }
     
    112109
    113110            try (
    114                 InputStream in = downloadConnection.getInputStream();
     111                InputStream in = downloadConnection.getContent();
    115112                OutputStream out = new FileOutputStream(file)
    116113            ) {
    117114                byte[] buffer = new byte[32768];
    118115                int count = 0;
    119                 int p1 = 0, p2 = 0;
     116                long p1 = 0, p2 = 0;
    120117                for (int read = in.read(buffer); read != -1; read = in.read(buffer)) {
    121118                    out.write(buffer, 0, read);
     
    124121                    p2 = 100 * count / size;
    125122                    if (p2 != p1) {
    126                         progressMonitor.setTicks(p2);
     123                        progressMonitor.setTicks((int) p2);
    127124                        p1 = p2;
    128125                    }
Note: See TracChangeset for help on using the changeset viewer.