Changeset 9174 in josm
- Timestamp:
- 2015-12-27T00:07:00+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r9172 r9174 152 152 } 153 153 154 activeConnection.uncompressAccordingToContentDisposition(uncompressAccordingToContentDisposition); 154 155 InputStream in = new ProgressInputStream(activeConnection, progressMonitor); 155 if (uncompressAccordingToContentDisposition) {156 activeConnection.uncompressAccordingToContentDisposition(true);157 }158 156 return in; 159 157 } catch (OsmTransferException e) { -
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r9173 r9174 183 183 } 184 184 in = "gzip".equalsIgnoreCase(getContentEncoding()) ? new GZIPInputStream(in) : in; 185 Compression compression = Compression.NONE; 185 186 if (uncompress) { 186 187 final String contentType = getContentType(); 187 188 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)) { 191 192 final String contentDisposition = getHeaderField("Content-Disposition"); 192 193 final Matcher matcher = Pattern.compile("filename=\"([^\"]+)\"").matcher(contentDisposition); 193 194 if (matcher.find()) { 194 195 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)); 196 197 } 197 198 } 199 in = compression.getUncompressedInputStream(in); 198 200 return in; 199 201 } -
trunk/test/unit/org/openstreetmap/josm/tools/UtilsTest.java
r8857 r9174 86 86 public void testOpenUrlGzip() throws IOException { 87 87 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()) { 89 90 Assert.assertTrue(x.readLine().startsWith("<?xml version=")); 90 91 } … … 98 99 public void testOpenUrlBzip() throws IOException { 99 100 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()) { 101 117 Assert.assertTrue(x.readLine().startsWith("<?xml version=")); 102 118 }
Note:
See TracChangeset
for help on using the changeset viewer.