Ignore:
Timestamp:
2007-05-07T23:26:58+02:00 (17 years ago)
Author:
framm
Message:

Support compressed downloads from the server (by announcing capability via appropriate Accept header). Set property osm-server.use-compression to false if you do not want compressed downloads. Based on Patch by Tom Hughes <tom@…>.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/io/OsmServerReader.java

    r225 r228  
    55import java.net.HttpURLConnection;
    66import java.net.URL;
     7import java.util.zip.Inflater;
     8import java.util.zip.InflaterInputStream;
     9import java.util.zip.GZIPInputStream;
    710
    811import org.openstreetmap.josm.Main;
     
    1013
    1114/**
    12  * This DataReader read directly from the REST API of the osm server.
     15 * This DataReader reads directly from the REST API of the osm server.
     16 *
     17 * It supports plain text transfer as well as gzip or deflate encoded transfers;
     18 * if compressed transfers are unwanted, set property osm-server.use-compression
     19 * to false.
    1320 *
    1421 * @author imi
     
    3239                        return null;
    3340                }
     41               
     42                if (Boolean.parseBoolean(Main.pref.get("osm-server.use-compression", "true")))
     43                        activeConnection.setRequestProperty("Accept-Encoding", "gzip, deflate");
     44
    3445                System.out.println("got return: "+activeConnection.getResponseCode());
    3546                activeConnection.setConnectTimeout(15000);
    3647                if (isAuthCancelled() && activeConnection.getResponseCode() == 401)
    3748                        return null;
    38                 return new ProgressInputStream(activeConnection, pleaseWaitDlg);
     49
     50                String encoding = activeConnection.getContentEncoding();
     51                InputStream inputStream = new ProgressInputStream(activeConnection, pleaseWaitDlg);
     52                if (encoding != null && encoding.equalsIgnoreCase("gzip")) {
     53                        inputStream = new GZIPInputStream(inputStream);
     54                }
     55                else if (encoding != null && encoding.equalsIgnoreCase("deflate")) {
     56                        inputStream = new InflaterInputStream(inputStream, new Inflater(true));
     57                }
     58                return inputStream;
    3959        }
    4060}
Note: See TracChangeset for help on using the changeset viewer.