Ignore:
Timestamp:
2015-12-26T23:41:54+01:00 (8 years ago)
Author:
simon04
Message:

see #12231 - HttpClient: add support to uncompress streams

File:
1 edited

Legend:

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

    r9168 r9169  
    1919import org.openstreetmap.josm.Main;
    2020import org.openstreetmap.josm.data.Version;
     21import org.openstreetmap.josm.io.Compression;
    2122
    2223/**
     
    115116        private final HttpURLConnection connection;
    116117        private final int responseCode;
     118        private boolean uncompress;
    117119
    118120        private Response(HttpURLConnection connection) throws IOException {
    119121            this.connection = connection;
    120122            this.responseCode = connection.getResponseCode();
     123        }
     124
     125        /**
     126         * Sets whether {@link #getContent()} should uncompress the input stream if necessary.
     127         *
     128         * @param uncompress whether the input stream should be uncompressed if necessary
     129         * @return {@code this}
     130         */
     131        public Response uncompress(boolean uncompress) {
     132            this.uncompress = uncompress;
     133            return this;
    121134        }
    122135
     
    135148                in = connection.getErrorStream();
    136149            }
    137             return "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in;
     150            in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in;
     151            if (uncompress) {
     152                return Compression.forContentType(getContentType()).getUncompressedInputStream(in);
     153            } else {
     154                return in;
     155            }
    138156        }
    139157
Note: See TracChangeset for help on using the changeset viewer.