Changeset 17862 in josm for trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
- Timestamp:
- 2021-05-06T17:39:27+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCachedTileLoaderJob.java
r17509 r17862 2 2 package org.openstreetmap.josm.data.cache; 3 3 4 import java.io.File; 4 5 import java.io.FileNotFoundException; 5 6 import java.io.IOException; 7 import java.io.InputStream; 6 8 import java.net.HttpURLConnection; 7 9 import java.net.URL; 10 import java.nio.file.Files; 8 11 import java.security.SecureRandom; 9 12 import java.util.Collections; … … 18 21 import java.util.regex.Matcher; 19 22 20 import org.apache.commons.jcs3.access.behavior.ICacheAccess;21 import org.apache.commons.jcs3.engine.behavior.ICacheElement;22 23 import org.openstreetmap.josm.data.cache.ICachedLoaderListener.LoadResult; 23 24 import org.openstreetmap.josm.data.imagery.TileJobOptions; … … 27 28 import org.openstreetmap.josm.tools.Logging; 28 29 import org.openstreetmap.josm.tools.Utils; 30 31 import org.apache.commons.jcs3.access.behavior.ICacheAccess; 32 import org.apache.commons.jcs3.engine.behavior.ICacheElement; 29 33 30 34 /** … … 295 299 attributes = new CacheEntryAttributes(); 296 300 } 301 final URL url = this.getUrlNoException(); 302 if (url == null) { 303 return false; 304 } 305 306 if (url.getProtocol().contains("http")) { 307 return loadObjectHttp(); 308 } 309 if (url.getProtocol().contains("file")) { 310 return loadObjectFile(url); 311 } 312 313 return false; 314 } 315 316 private boolean loadObjectFile(URL url) { 317 String fileName = url.toExternalForm(); 318 File file = new File(fileName.substring("file:/".length() - 1)); 319 if (!file.exists()) { 320 file = new File(fileName.substring("file://".length() - 1)); 321 } 322 try (InputStream fileInputStream = Files.newInputStream(file.toPath())) { 323 cacheData = createCacheEntry(Utils.readBytesFromStream(fileInputStream)); 324 cache.put(getCacheKey(), cacheData, attributes); 325 return true; 326 } catch (IOException e) { 327 Logging.error(e); 328 attributes.setError(e); 329 attributes.setException(e); 330 } 331 return false; 332 } 333 334 /** 335 * @return true if object was successfully downloaded via http, false, if there was a loading failure 336 */ 337 private boolean loadObjectHttp() { 297 338 try { 298 339 // if we have object in cache, and host doesn't support If-Modified-Since nor If-None-Match … … 554 595 return getUrl(); 555 596 } catch (IOException e) { 597 Logging.trace(e); 556 598 return null; 557 599 }
Note:
See TracChangeset
for help on using the changeset viewer.
