org.openstreetmap.gui.jmapviewer
Class OsmFileCacheTileLoader

java.lang.Object
  extended by org.openstreetmap.gui.jmapviewer.OsmTileLoader
      extended by org.openstreetmap.gui.jmapviewer.OsmFileCacheTileLoader
All Implemented Interfaces:
TileLoader

public class OsmFileCacheTileLoader
extends OsmTileLoader

A TileLoader implementation that loads tiles from OSM via HTTP and saves all loaded files in a directory located in the temporary directory. If a tile is present in this file cache it will not be loaded from OSM again.


Nested Class Summary
protected  class OsmFileCacheTileLoader.FileLoadJob
           
static interface OsmFileCacheTileLoader.TileClearController
           
 
Field Summary
protected  java.lang.String cacheDirBase
           
private static java.lang.String ETAG_FILE_EXT
           
static long FILE_AGE_ONE_DAY
           
static long FILE_AGE_ONE_WEEK
           
private static java.util.logging.Logger log
           
protected  long maxCacheFileAge
           
protected  long recheckAfter
           
protected  java.util.Map<TileSource,java.io.File> sourceCacheDirMap
           
private static java.nio.charset.Charset TAGS_CHARSET
           
private static java.lang.String TAGS_FILE_EXT
           
 
Fields inherited from class org.openstreetmap.gui.jmapviewer.OsmTileLoader
headers, listener, timeoutConnect, timeoutRead
 
Constructor Summary
OsmFileCacheTileLoader(TileLoaderListener map)
          Create a OSMFileCacheTileLoader with system property temp dir.
OsmFileCacheTileLoader(TileLoaderListener map, java.io.File cacheDir)
          Create a OSMFileCacheTileLoader with given cache directory.
 
Method Summary
 void clearCache(TileSource source)
           
 void clearCache(TileSource source, OsmFileCacheTileLoader.TileClearController controller)
           
 TileJob createTileLoaderJob(Tile tile)
          A typical implementation of this function should create and return a new TileJob instance that performs the load action.
 java.lang.String getCacheDirBase()
           
static java.io.File getDefaultCacheDir()
           
 long getMaxFileAge()
           
protected  java.io.File getSourceCacheDir(TileSource source)
           
 void setCacheMaxFileAge(long maxFileAge)
          Sets the maximum age of the local cached tile in the file system.
 void setTileCacheDir(java.lang.String tileCacheDir)
           
 
Methods inherited from class org.openstreetmap.gui.jmapviewer.OsmTileLoader
loadTileFromOsm, loadTileMetadata, prepareHttpUrlConnection, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

private static final java.util.logging.Logger log

ETAG_FILE_EXT

private static final java.lang.String ETAG_FILE_EXT
See Also:
Constant Field Values

TAGS_FILE_EXT

private static final java.lang.String TAGS_FILE_EXT
See Also:
Constant Field Values

TAGS_CHARSET

private static final java.nio.charset.Charset TAGS_CHARSET

FILE_AGE_ONE_DAY

public static final long FILE_AGE_ONE_DAY
See Also:
Constant Field Values

FILE_AGE_ONE_WEEK

public static final long FILE_AGE_ONE_WEEK
See Also:
Constant Field Values

cacheDirBase

protected java.lang.String cacheDirBase

sourceCacheDirMap

protected final java.util.Map<TileSource,java.io.File> sourceCacheDirMap

maxCacheFileAge

protected long maxCacheFileAge

recheckAfter

protected long recheckAfter
Constructor Detail

OsmFileCacheTileLoader

public OsmFileCacheTileLoader(TileLoaderListener map,
                              java.io.File cacheDir)
                       throws java.io.IOException
Create a OSMFileCacheTileLoader with given cache directory. If cacheDir is not set or invalid, IOException will be thrown.

Parameters:
map - the listener checking for tile load events (usually the map for display)
cacheDir - directory to store cached tiles
Throws:
java.io.IOException

OsmFileCacheTileLoader

public OsmFileCacheTileLoader(TileLoaderListener map)
                       throws java.lang.SecurityException,
                              java.io.IOException
Create a OSMFileCacheTileLoader with system property temp dir. If not set an IOException will be thrown.

Parameters:
map - the listener checking for tile load events (usually the map for display)
Throws:
java.lang.SecurityException
java.io.IOException
Method Detail

getDefaultCacheDir

public static java.io.File getDefaultCacheDir()
                                       throws java.lang.SecurityException
Throws:
java.lang.SecurityException

createTileLoaderJob

public TileJob createTileLoaderJob(Tile tile)
Description copied from interface: TileLoader
A typical implementation of this function should create and return a new TileJob instance that performs the load action.

Specified by:
createTileLoaderJob in interface TileLoader
Overrides:
createTileLoaderJob in class OsmTileLoader
Parameters:
tile - the tile to be loaded
Returns:
TileJob implementation that performs the desired load action.

getSourceCacheDir

protected java.io.File getSourceCacheDir(TileSource source)

getMaxFileAge

public long getMaxFileAge()

setCacheMaxFileAge

public void setCacheMaxFileAge(long maxFileAge)
Sets the maximum age of the local cached tile in the file system. If a local tile is older than the specified file age OsmFileCacheTileLoader will connect to the tile server and check if a newer tile is available using the mechanism specified for the selected tile source/server.

Parameters:
maxFileAge - maximum age in milliseconds
See Also:
FILE_AGE_ONE_DAY, FILE_AGE_ONE_WEEK, TileSource.getTileUpdate()

getCacheDirBase

public java.lang.String getCacheDirBase()

setTileCacheDir

public void setTileCacheDir(java.lang.String tileCacheDir)

clearCache

public void clearCache(TileSource source)

clearCache

public void clearCache(TileSource source,
                       OsmFileCacheTileLoader.TileClearController controller)


JOSM