Changeset 9538 in osm for applications/viewer/jmapviewer/src/org/openstreetmap
- Timestamp:
- 2008-08-07T15:41:48+02:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/viewer/jmapviewer/src/org/openstreetmap/gui/jmapviewer/OsmFileCacheTileLoader.java
r9494 r9538 13 13 import java.net.URL; 14 14 import java.net.URLConnection; 15 import java.util.Date;16 15 17 16 import javax.imageio.ImageIO; 18 17 19 import org.openstreetmap.gui.jmapviewer.interfaces.Job;20 18 import org.openstreetmap.gui.jmapviewer.interfaces.TileCache; 21 19 import org.openstreetmap.gui.jmapviewer.interfaces.TileLoader; … … 37 35 protected String tileCacheDir; 38 36 39 protected long maxFileAge = 0;// FILE_AGE_ONE_DAY;// 40 41 // FILE_AGE_ONE_WEEK; 37 protected long maxFileAge = FILE_AGE_ONE_WEEK; 42 38 43 39 public OsmFileCacheTileLoader(JMapViewer map, String baseUrl) { … … 66 62 } 67 63 68 protected class FileLoadJob implements Job{64 protected class FileLoadJob implements Runnable { 69 65 InputStream input = null; 70 66 … … 104 100 return; 105 101 } 106 System.out.println("Cache hit for " + tile + " but file age is high: " 107 + new Date(fileAge)); 102 // System.out.println("Cache hit for " + tile + 103 // " but file age is high: " 104 // + new Date(fileAge)); 108 105 map.repaint(); 109 106 // if (!isOsmTileNewer(tile, fileAge)) { … … 121 118 } 122 119 // Thread.sleep(500); 123 System.out.println("Loading tile from OSM: " + tile);120 // System.out.println("Loading tile from OSM: " + tile); 124 121 HttpURLConnection urlConn = loadTileFromOsm(tile); 125 if (fileAge > 0)126 127 128 if (urlConn.getResponseCode() == 304) {129 130 131 132 }122 // if (fileAge > 0) 123 // urlConn.setIfModifiedSince(fileAge); 124 // 125 // if (urlConn.getResponseCode() == 304) { 126 // System.out.println("Local version is up to date"); 127 // tile.setLoaded(true); 128 // return; 129 // } 133 130 byte[] buffer = loadTileInBuffer(urlConn); 134 131 tile.setImage(ImageIO.read(new ByteArrayInputStream(buffer))); … … 161 158 } 162 159 160 /** 161 * Performs a <code>HEAD</code> request for retrieving the 162 * <code>LastModified</code> header value. 163 * 164 * Note: This does only work with servers providing the 165 * <code>LastModified</code> header: 166 * <ul> 167 * <li>{@link OsmTileLoader#MAP_OSMA} - supported</li> 168 * <li>{@link OsmTileLoader#MAP_MAPNIK} - not supported</li> 169 * </ul> 170 * 171 * @param tile 172 * @param fileAge 173 * @return <code>true</code> if the tile on the server is newer than the 174 * file 175 * @throws IOException 176 */ 163 177 protected boolean isOsmTileNewer(Tile tile, long fileAge) throws IOException { 164 178 URL url; … … 167 181 urlConn.setRequestMethod("HEAD"); 168 182 urlConn.setReadTimeout(30000); // 30 seconds read 169 System.out.println("Tile age: " + new Date(urlConn.getLastModified()) + " / " 170 + new Date(fileAge)); 183 // System.out.println("Tile age: " + new 184 // Date(urlConn.getLastModified()) + " / " 185 // + new Date(fileAge)); 171 186 long lastModified = urlConn.getLastModified(); 172 187 if (lastModified == 0) … … 192 207 } 193 208 } 194 195 /** 196 * Terminating all transfers that are currently in progress 197 */ 198 public void stop() { 199 200 try { 201 // if (input != null) 202 // input.stop(); 203 } catch (Exception e) { 204 } 205 } 206 } 207 209 } 210 211 public long getMaxFileAge() { 212 return maxFileAge; 213 } 214 215 /** 216 * Sets the maximum age of the local cached tile in the file system. 217 * 218 * @param maxFileAge 219 * maximum age in milliseconds 220 * @see #FILE_AGE_ONE_DAY 221 * @see #FILE_AGE_ONE_WEEK 222 */ 223 public void setMaxFileAge(long maxFileAge) { 224 this.maxFileAge = maxFileAge; 225 } 226 227 public String getTileCacheDir() { 228 return tileCacheDir; 229 } 230 231 public void setTileCacheDir(String tileCacheDir) { 232 this.tileCacheDir = tileCacheDir; 233 } 234 235 208 236 }
Note:
See TracChangeset
for help on using the changeset viewer.