Changeset 26909 in osm for applications/viewer/jmapviewer/src/org/openstreetmap/gui
- Timestamp:
- 2011-10-20T01:43:00+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r26529 r26909 20 20 import java.net.URLConnection; 21 21 import java.nio.charset.Charset; 22 import java.util.HashMap; 23 import java.util.Map; 22 24 import java.util.Map.Entry; 23 25 import java.util.Random; … … 52 54 53 55 protected String cacheDirBase; 56 57 protected final Map<TileSource, File> sourceCacheDirMap; 54 58 55 59 protected long maxCacheFileAge = FILE_AGE_ONE_WEEK; … … 96 100 log.finest("Tile cache directory: " + cacheDir); 97 101 cacheDirBase = cacheDir.getAbsolutePath(); 102 sourceCacheDirMap = new HashMap<TileSource, File>(); 98 103 } 99 104 … … 112 117 } 113 118 119 protected File getSourceCacheDir(TileSource source) { 120 File dir = sourceCacheDirMap.get(source); 121 if (dir == null) { 122 dir = new File(cacheDirBase, source.getName().replaceAll("[\\\\/:*?\"<>|]", "_")); 123 if (!dir.exists()) { 124 dir.mkdirs(); 125 } 126 } 127 return dir; 128 } 129 114 130 protected class FileLoadJob implements Runnable { 115 131 InputStream input = null; … … 140 156 tile.loading = true; 141 157 } 142 tileCacheDir = new File(cacheDirBase, source.getName().replaceAll("[\\\\/:*?\"<>|]", "_")); 143 if (!tileCacheDir.exists()) { 144 tileCacheDir.mkdirs(); 145 } 158 tileCacheDir = getSourceCacheDir(source); 146 159 if (loadTileFromFile()) 147 160 return; … … 463 476 this.cacheDirBase = dir.getAbsolutePath(); 464 477 } 465 478 479 public void clearCache(TileSource source) { 480 File dir = getSourceCacheDir(source); 481 if (dir.isDirectory()) { 482 for (File file : dir.listFiles()) { 483 file.delete(); 484 } 485 } 486 dir.delete(); 487 } 466 488 }
Note:
See TracChangeset
for help on using the changeset viewer.