Package gov.nasa.worldwind.data
Class CachedDataRaster
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.data.CachedDataRaster
-
- All Implemented Interfaces:
AVList,DataRaster,Disposable
public class CachedDataRaster extends AVListImpl implements DataRaster
TheCachedDataRasteris used to hold data raster's source and metadata, while the actual data raster may not be loaded in to the memory. This is mostly used together with a memory caches.CachedDataRasteractually implements all interfaces of theDataRaster, and acts as a proxy, that loads a real data raster only when it is actually needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classCachedDataRaster.ErrorHandlerMode
-
Field Summary
Fields Modifier and Type Field Description protected MemoryCache.CacheListenercacheListenerprotected DataRasterReaderdataReaderprotected java.lang.ObjectdataSourceprotected MemoryCacherasterCacheprotected java.lang.ObjectrasterRetrievalLockprotected java.lang.ObjectrasterUsageLockprotected java.lang.String[]requiredKeys
-
Constructor Summary
Constructors Constructor Description CachedDataRaster(java.lang.Object source, AVList params, DataRasterReader reader, MemoryCache cache)Create a cached data raster.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassembleMetadata(java.lang.Object source, AVList params, DataRasterReader reader)protected java.lang.StringcomposeExceptionReason(java.lang.Throwable t)voiddispose()Disposes of any internal resources allocated by the object.protected static voiddisposeRasters(DataRaster[] rasters)voiddrawOnTo(DataRaster canvas)Copies this raster into a specified raster.DataRasterReadergetDataRasterReader()protected DataRaster[]getDataRasters()java.lang.ObjectgetDataSource()intgetHeight()Returns the raster's height in raster units.AVListgetMetadata()AVListgetParams()protected java.lang.String[]getRequiredKeysList()SectorgetSector()Returns the region covered be the data.protected longgetSizeInBytes(DataRaster[] rasters)DataRastergetSubRaster(int width, int height, Sector sector, AVList params)Returns a portion of this raster as another raster.DataRastergetSubRaster(AVList params)Returns a portion of this raster as another raster.protected static longgetTotalUsedMemory()intgetWidth()Returns the raster's width in raster units.protected booleanhasRequiredMetadata(AVList params, CachedDataRaster.ErrorHandlerMode throwException)Validates if params (AVList) has all required keys.protected voidreleaseMemory()-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
-
-
-
Field Detail
-
dataSource
protected java.lang.Object dataSource
-
dataReader
protected DataRasterReader dataReader
-
rasterCache
protected MemoryCache rasterCache
-
cacheListener
protected MemoryCache.CacheListener cacheListener
-
rasterUsageLock
protected final java.lang.Object rasterUsageLock
-
rasterRetrievalLock
protected final java.lang.Object rasterRetrievalLock
-
requiredKeys
protected java.lang.String[] requiredKeys
-
-
Constructor Detail
-
CachedDataRaster
public CachedDataRaster(java.lang.Object source, AVList params, DataRasterReader reader, MemoryCache cache) throws java.io.IOException, java.lang.IllegalArgumentExceptionCreate a cached data raster.- Parameters:
source- the location of the local file, expressed as either a String path, a File, or a file URL.params- metadata as AVList, it is expected to next parameters: AVKey.WIDTH, AVKey.HEIGHT, AVKey.SECTOR, AVKey.PIXEL_FORMAT.If any of these keys is missing, there will be an attempt made to retrieve missign metadata from the source using the reader.
reader- A reference to a DataRasterReader instancecache- A reference to a MemoryCache instance- Throws:
java.io.IOException- thrown if there is an error to read metadata from the sourcejava.lang.IllegalArgumentException- thrown when a source or a reader are null
-
-
Method Detail
-
assembleMetadata
protected void assembleMetadata(java.lang.Object source, AVList params, DataRasterReader reader) throws java.io.IOException, java.lang.IllegalArgumentException- Throws:
java.io.IOExceptionjava.lang.IllegalArgumentException
-
getRequiredKeysList
protected java.lang.String[] getRequiredKeysList()
-
hasRequiredMetadata
protected boolean hasRequiredMetadata(AVList params, CachedDataRaster.ErrorHandlerMode throwException) throws java.lang.IllegalArgumentException
Validates if params (AVList) has all required keys.- Parameters:
params- AVList of key/value pairsthrowException- specifies weather to throw exception when a key/value is missing, or just return false.- Returns:
- TRUE, if all required keys are present in the params list, or both params and required keys are empty, otherwise returns FALSE (if throwException is false)
- Throws:
java.lang.IllegalArgumentException- If a key/value is missing and throwException is set to TRUE
-
getWidth
public int getWidth()
Description copied from interface:DataRasterReturns the raster's width in raster units.- Specified by:
getWidthin interfaceDataRaster- Returns:
- the raster's width in raster units.
-
getHeight
public int getHeight()
Description copied from interface:DataRasterReturns the raster's height in raster units.- Specified by:
getHeightin interfaceDataRaster- Returns:
- the raster's height in raster units.
-
getSector
public Sector getSector()
Description copied from interface:DataRasterReturns the region covered be the data.- Specified by:
getSectorin interfaceDataRaster- Returns:
- a sector indicating the region covered by the raster.
-
getDataSource
public java.lang.Object getDataSource()
-
getParams
public AVList getParams()
-
getMetadata
public AVList getMetadata()
-
getDataRasterReader
public DataRasterReader getDataRasterReader()
-
dispose
public void dispose()
Description copied from interface:DisposableDisposes of any internal resources allocated by the object.- Specified by:
disposein interfaceDisposable
-
getDataRasters
protected DataRaster[] getDataRasters() throws java.io.IOException, WWRuntimeException
- Throws:
java.io.IOExceptionWWRuntimeException
-
drawOnTo
public void drawOnTo(DataRaster canvas)
Description copied from interface:DataRasterCopies this raster into a specified raster.- Specified by:
drawOnToin interfaceDataRaster- Parameters:
canvas- - the raster to copy into.
-
getSubRaster
public DataRaster getSubRaster(AVList params)
Description copied from interface:DataRasterReturns a portion of this raster as another raster. Input values are the desired width and height of the return sub-raster, and the sector to copy from this raster to the sub-raster. The returned raster conforms to EPSG:4326 even if this raster does not.- Specified by:
getSubRasterin interfaceDataRaster- Parameters:
params- a list of parameters that specify the width, height and sector of the region to return. Specify these values usingAVKey.WIDTH,AVKey.HEIGHTandAVKey.SECTOR.- Returns:
- the requested raster, or null if the raster could not be created.
-
getSubRaster
public DataRaster getSubRaster(int width, int height, Sector sector, AVList params)
Description copied from interface:DataRasterReturns a portion of this raster as another raster. The returned raster conforms to EPSG:4326 even if this raster does not.- Specified by:
getSubRasterin interfaceDataRaster- Parameters:
width- the width to make the returned sub-raster.height- the height to make the returned sub-raster.sector- the sector to copy.params- a list of parameters that specify the width, height and sector of the region to return. Specify these values usingAVKey.WIDTH,AVKey.HEIGHTandAVKey.SECTOR.- Returns:
- the requested raster, or null if the raster could not be created.
-
releaseMemory
protected void releaseMemory()
-
composeExceptionReason
protected java.lang.String composeExceptionReason(java.lang.Throwable t)
-
getSizeInBytes
protected long getSizeInBytes(DataRaster[] rasters)
-
disposeRasters
protected static void disposeRasters(DataRaster[] rasters)
-
getTotalUsedMemory
protected static long getTotalUsedMemory()
-
-