Ignore:
Timestamp:
2015-12-31T03:24:56+01:00 (8 years ago)
Author:
Don-vip
Message:

OAuth: add robustness, basic unit test, code cleanup

File:
1 edited

Legend:

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

    r9200 r9227  
    231231         * @see HttpURLConnection#getErrorStream()
    232232         */
     233        @SuppressWarnings("resource")
    233234        public InputStream getContent() throws IOException {
    234235            InputStream in;
     
    238239                in = connection.getErrorStream();
    239240            }
    240             in = new ProgressInputStream(in, getContentLength(), monitor);
    241             in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in;
    242             Compression compression = Compression.NONE;
    243             if (uncompress) {
    244                 final String contentType = getContentType();
    245                 Main.debug("Uncompressing input stream according to Content-Type header: {0}", contentType);
    246                 compression = Compression.forContentType(contentType);
    247             }
    248             if (uncompressAccordingToContentDisposition && Compression.NONE.equals(compression)) {
    249                 final String contentDisposition = getHeaderField("Content-Disposition");
    250                 final Matcher matcher = Pattern.compile("filename=\"([^\"]+)\"").matcher(contentDisposition);
    251                 if (matcher.find()) {
    252                     Main.debug("Uncompressing input stream according to Content-Disposition header: {0}", contentDisposition);
    253                     compression = Compression.byExtension(matcher.group(1));
     241            if (in != null) {
     242                in = new ProgressInputStream(in, getContentLength(), monitor);
     243                in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in;
     244                Compression compression = Compression.NONE;
     245                if (uncompress) {
     246                    final String contentType = getContentType();
     247                    Main.debug("Uncompressing input stream according to Content-Type header: {0}", contentType);
     248                    compression = Compression.forContentType(contentType);
    254249                }
    255             }
    256             in = compression.getUncompressedInputStream(in);
     250                if (uncompressAccordingToContentDisposition && Compression.NONE.equals(compression)) {
     251                    final String contentDisposition = getHeaderField("Content-Disposition");
     252                    final Matcher matcher = Pattern.compile("filename=\"([^\"]+)\"").matcher(contentDisposition);
     253                    if (matcher.find()) {
     254                        Main.debug("Uncompressing input stream according to Content-Disposition header: {0}", contentDisposition);
     255                        compression = Compression.byExtension(matcher.group(1));
     256                    }
     257                }
     258                in = compression.getUncompressedInputStream(in);
     259            }
    257260            return in;
    258261        }
Note: See TracChangeset for help on using the changeset viewer.