Changeset 9174 in josm


Ignore:
Timestamp:
2015-12-27T00:07:00+01:00 (8 years ago)
Author:
simon04
Message:

see #12231 - Update unit tests, fix regression

Location:
trunk
Files:
3 edited

Legend:

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

    r9172 r9174  
    152152                }
    153153
     154                activeConnection.uncompressAccordingToContentDisposition(uncompressAccordingToContentDisposition);
    154155                InputStream in = new ProgressInputStream(activeConnection, progressMonitor);
    155                 if (uncompressAccordingToContentDisposition) {
    156                     activeConnection.uncompressAccordingToContentDisposition(true);
    157                 }
    158156                return in;
    159157            } catch (OsmTransferException e) {
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r9173 r9174  
    183183            }
    184184            in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in;
     185            Compression compression = Compression.NONE;
    185186            if (uncompress) {
    186187                final String contentType = getContentType();
    187188                Main.debug("Uncompressing input stream according to Content-Type header: {0}", contentType);
    188                 in = Compression.forContentType(contentType).getUncompressedInputStream(in);
    189             }
    190             if (uncompressAccordingToContentDisposition) {
     189                compression = Compression.forContentType(contentType);
     190            }
     191            if (uncompressAccordingToContentDisposition && Compression.NONE.equals(compression)) {
    191192                final String contentDisposition = getHeaderField("Content-Disposition");
    192193                final Matcher matcher = Pattern.compile("filename=\"([^\"]+)\"").matcher(contentDisposition);
    193194                if (matcher.find()) {
    194195                    Main.debug("Uncompressing input stream according to Content-Disposition header: {0}", contentDisposition);
    195                     in = Compression.byExtension(matcher.group(1)).getUncompressedInputStream(in);
     196                    compression = Compression.byExtension(matcher.group(1));
    196197                }
    197198            }
     199            in = compression.getUncompressedInputStream(in);
    198200            return in;
    199201        }
  • trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java

    r8857 r9174  
    8686    public void testOpenUrlGzip() throws IOException {
    8787        Main.initApplicationPreferences();
    88         try (BufferedReader x = Utils.openURLReaderAndDecompress(new URL("https://www.openstreetmap.org/trace/1613906/data"), true)) {
     88        final URL url = new URL("https://www.openstreetmap.org/trace/1613906/data");
     89        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
    8990            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
    9091        }
     
    9899    public void testOpenUrlBzip() throws IOException {
    99100        Main.initApplicationPreferences();
    100         try (BufferedReader x = Utils.openURLReaderAndDecompress(new URL("https://www.openstreetmap.org/trace/785544/data"), true)) {
     101        final URL url = new URL("https://www.openstreetmap.org/trace/785544/data");
     102        try (BufferedReader x = HttpClient.create(url).connect().uncompress(true).getContentReader()) {
     103            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
     104        }
     105    }
     106
     107    /**
     108     * Test of {@link Utils#openURLReaderAndDecompress} method with Bzip compression.
     109     * @throws IOException if any I/O error occurs
     110     */
     111    @Test
     112    public void testTicket9660() throws IOException {
     113        Main.initApplicationPreferences();
     114        final URL url = new URL("http://www.openstreetmap.org/trace/1350010/data");
     115        try (BufferedReader x = HttpClient.create(url).connect()
     116                .uncompress(true).uncompressAccordingToContentDisposition(true).getContentReader()) {
    101117            Assert.assertTrue(x.readLine().startsWith("<?xml version="));
    102118        }
Note: See TracChangeset for help on using the changeset viewer.