- Timestamp:
- 2014-02-02T23:23:27+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r6643 r6803 184 184 // TODO: handle multiple suitable tasks ? 185 185 try { 186 future = tasks.iterator().next().loadUrl(new_layer, url, monitor); 186 task = tasks.iterator().next(); 187 future = task.loadUrl(new_layer, url, monitor); 187 188 } catch (IllegalArgumentException e) { 188 189 Main.error(e); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r6380 r6803 59 59 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 60 60 downloadTask = new DownloadTask(newLayer, 61 new BoundingBoxDownloader(downloadArea), progressMonitor , false);61 new BoundingBoxDownloader(downloadArea), progressMonitor); 62 62 // We need submit instead of execute so we can wait for it to finish and get the error 63 63 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 70 70 if (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE)) { 71 71 downloadTask = new DownloadTask(newLayer, 72 new OsmServerLocationReader(url), progressMonitor , url.matches(PATTERN_TRACE_ID));72 new OsmServerLocationReader(url), progressMonitor); 73 73 // Extract .gpx filename from URL to set the new layer name 74 74 Matcher matcher = Pattern.compile(PATTERN_EXTERNAL_GPX_FILE).matcher(url); … … 99 99 private GpxData rawData; 100 100 private final boolean newLayer; 101 private final boolean compressed; 102 103 public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor, boolean compressed) { 101 102 public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) { 104 103 super(tr("Downloading GPS data")); 105 104 this.reader = reader; 106 105 this.newLayer = newLayer; 107 this.compressed = compressed;108 106 } 109 107 … … 113 111 return; 114 112 ProgressMonitor subMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 115 if (compressed) { 116 rawData = reader.parseRawGpsBzip2(subMonitor); 117 } else { 118 rawData = reader.parseRawGps(subMonitor); 119 } 113 rawData = reader.parseRawGps(subMonitor); 120 114 } catch(Exception e) { 121 115 if (isCanceled()) -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r6716 r6803 138 138 @Override 139 139 public GpxData parse() throws OsmTransferException, IllegalDataException, IOException, SAXException { 140 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true) );140 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true), null, true); 141 141 if (in == null) 142 142 return null; -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r6787 r6803 11 11 import java.net.MalformedURLException; 12 12 import java.net.URL; 13 import java.util.List; 14 import java.util.Map; 13 15 import java.util.zip.GZIPInputStream; 14 16 import java.util.zip.Inflater; … … 98 100 */ 99 101 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason) throws OsmTransferException { 102 return getInputStreamRaw(urlStr, progressMonitor, reason, false); 103 } 104 105 /** 106 * Open a connection to the given url and return a reader on the input stream 107 * from that connection. In case of user cancel, return <code>null</code>. 108 * @param urlStr The exact url to connect to. 109 * @param progressMonitor progress monitoring and abort handler 110 * @param reason The reason to show on console. Can be {@code null} if no reason is given 111 * @param uncompressAccordingToContentDisposition Whether to inspect the HTTP header {@code Content-Disposition} 112 * for {@code filename} and uncompress a gzip/bzip2 stream. 113 * @return An reader reading the input stream (servers answer) or <code>null</code>. 114 * @throws OsmTransferException thrown if data transfer errors occur 115 */ 116 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor, String reason, boolean uncompressAccordingToContentDisposition) throws OsmTransferException { 100 117 try { 101 118 URL url = null; … … 141 158 } 142 159 try { 160 Main.debug(activeConnection.getHeaderFields().toString()); 143 161 if (activeConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) 144 162 throw new OsmApiException(HttpURLConnection.HTTP_UNAUTHORIZED,null,null); … … 169 187 } 170 188 171 return fixEncoding(new ProgressInputStream(activeConnection, progressMonitor), encoding); 189 InputStream in = new ProgressInputStream(activeConnection, progressMonitor); 190 if (uncompressAccordingToContentDisposition) { 191 in = uncompressAccordingToContentDisposition(in, activeConnection.getHeaderFields()); 192 } 193 return fixEncoding(in, encoding); 172 194 } catch (OsmTransferException e) { 173 195 throw e; … … 189 211 } 190 212 213 private InputStream uncompressAccordingToContentDisposition(InputStream stream, Map<String, List<String>> headerFields) throws IOException { 214 if (headerFields.get("Content-Disposition").toString().contains(".gz\"")) { 215 return Compression.GZIP.getUncompressedInputStream(stream); 216 } else if (headerFields.get("Content-Disposition").toString().contains(".bz2\"")) { 217 return Compression.BZIP2.getUncompressedInputStream(stream); 218 } else { 219 return stream; 220 } 221 } 222 191 223 /** 192 224 * Download OSM files from somewhere
Note:
See TracChangeset
for help on using the changeset viewer.