deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

org.deegree.coverage.raster.cache
Class CacheRasterReader

java.lang.Object
  extended by org.deegree.coverage.raster.io.grid.GridReader
      extended by org.deegree.coverage.raster.io.grid.GridFileReader
          extended by org.deegree.coverage.raster.cache.CacheRasterReader
All Implemented Interfaces:
RasterReader

public class CacheRasterReader
extends GridFileReader

The CacheRasterFile is a grid based caching mechanism for raster readers.

Version:
$Revision: 22035 $, $Date: 2010-01-20 15:01:15 +0100 (Mi, 20 Jan 2010) $
Author:
Rutger Bezema, last edited by: $Author: aschmitz $

Field Summary
 
Fields inherited from class org.deegree.coverage.raster.io.grid.GridReader
infoFile, sampleSize
 
Constructor Summary
CacheRasterReader(ByteBuffer filledBuffer, int width, int height, File cacheFile, boolean shouldCreateCachefile, RasterDataInfo dataInfo, RasterGeoReference geoReference, RasterCache cache)
          Create a cached raster from the given bytebuffer.
CacheRasterReader(RasterReader cachedReader, File cacheFile, RasterCache cache)
           
 
Method Summary
 boolean canLoad(File filename)
          Check if the raster reader is able to read the given raster file.
static CacheRasterReader createFromCache(RasterReader reader, File cacheFile, RasterCache cache)
          Creates a CachedRasterReader from the given cacheFile.
 long currentApproxMemory()
           
 void dispose()
          Signals the reader that it should try to dispose all in memory data.
 long dispose(boolean memoryBuffersAsWell)
          Causes the cachefile to be written (if existing) and the memory buffers to be set to null.
 boolean equals(Object other)
           
 void flush()
          Writes all current in memory byte buffers to the cache file (if existing).
 String getDataLocationId()
           
 RasterGeoReference getGeoReference()
           
 int getHeight()
           
 Set<String> getSupportedFormats()
           
 int getWidth()
           
 long lastReadAccess()
          Return the current time millis of the last read action.
 AbstractRaster load(File gridFile, RasterIOOptions options)
          Read the given raster file into an abstract raster.
 AbstractRaster load(InputStream stream, RasterIOOptions options)
          Read the given input stream into an abstract raster.
protected  void read(int columnId, int rowId, ByteBuffer buffer)
          Reads the data from the grid.
 BufferResult read(RasterRect rect, ByteBuffer resultBuffer)
           
 boolean shouldCreateCacheFile()
           
 
Methods inherited from class org.deegree.coverage.raster.io.grid.GridFileReader
file, instantiate, leaveStreamOpen, readValuesFromTile
 
Methods inherited from class org.deegree.coverage.raster.io.grid.GridReader
allocateTileBuffer, canReadTiles, getBytesPerTile, getEnvelope, getIntersectingTiles, getNumberOfTiles, getRasterDataInfo, getTile, getTileColumns, getTileData, getTileEnvelope, getTileId, getTileRasterHeight, getTileRasterWidth, getTileRows, getTilesPerBlob, instantiate, setTilesPerBlob, snapToGrid
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheRasterReader

public CacheRasterReader(ByteBuffer filledBuffer,
                         int width,
                         int height,
                         File cacheFile,
                         boolean shouldCreateCachefile,
                         RasterDataInfo dataInfo,
                         RasterGeoReference geoReference,
                         RasterCache cache)
Create a cached raster from the given bytebuffer.

Parameters:
filledBuffer - with values.
width - of the raster for which this buffer is valid.
height - of the raster for which this buffer is valid.
cacheFile - to use for storage
shouldCreateCachefile - if writing to disk should be enabled.
dataInfo - defining the data
geoReference - of the raster
cache - used.

CacheRasterReader

public CacheRasterReader(RasterReader cachedReader,
                         File cacheFile,
                         RasterCache cache)
Parameters:
cachedReader -
cacheFile -
cache -
Method Detail

createFromCache

public static CacheRasterReader createFromCache(RasterReader reader,
                                                File cacheFile,
                                                RasterCache cache)
Creates a CachedRasterReader from the given cacheFile.

Parameters:
reader - which backs the cache
cacheFile - to instantiate from
cache - manager to use.
Returns:
a CacheRasterReader or null if the cacheFile could not be read.

load

public AbstractRaster load(File gridFile,
                           RasterIOOptions options)
                    throws IOException
Description copied from interface: RasterReader
Read the given raster file into an abstract raster.

Specified by:
load in interface RasterReader
Overrides:
load in class GridFileReader
Returns:
the loaded raster
Throws:
IOException - may be thrown when there is a problem with reading the raster.

read

protected void read(int columnId,
                    int rowId,
                    ByteBuffer buffer)
             throws IOException
Description copied from class: GridReader
Reads the data from the grid.

Overrides:
read in class GridFileReader
Throws:
IOException

read

public BufferResult read(RasterRect rect,
                         ByteBuffer resultBuffer)
                  throws IOException
Specified by:
read in interface RasterReader
Overrides:
read in class GridFileReader
Parameters:
rect - to read.
resultBuffer - to store the result in
Returns:
the read buffer and its domain
Throws:
IOException

canLoad

public boolean canLoad(File filename)
Description copied from interface: RasterReader
Check if the raster reader is able to read the given raster file.

Specified by:
canLoad in interface RasterReader
Overrides:
canLoad in class GridFileReader
Returns:
true if the class can read the raster

getSupportedFormats

public Set<String> getSupportedFormats()
Specified by:
getSupportedFormats in interface RasterReader
Overrides:
getSupportedFormats in class GridFileReader
Returns:
a Set of (image) formats mime/types the implementation is able to read.

load

public AbstractRaster load(InputStream stream,
                           RasterIOOptions options)
                    throws IOException
Description copied from interface: RasterReader
Read the given input stream into an abstract raster.

Specified by:
load in interface RasterReader
Overrides:
load in class GridReader
Returns:
the loaded raster
Throws:
IOException - may be thrown when there is a problem with reading the raster.

shouldCreateCacheFile

public boolean shouldCreateCacheFile()
Specified by:
shouldCreateCacheFile in interface RasterReader
Overrides:
shouldCreateCacheFile in class GridReader
Returns:
true if a cache file should be created for the read raster.

getGeoReference

public RasterGeoReference getGeoReference()
Specified by:
getGeoReference in interface RasterReader
Overrides:
getGeoReference in class GridReader
Returns:
the geo reference of the read raster

getHeight

public int getHeight()
Specified by:
getHeight in interface RasterReader
Overrides:
getHeight in class GridReader
Returns:
the height (in pixels) of the read raster

getWidth

public int getWidth()
Specified by:
getWidth in interface RasterReader
Overrides:
getWidth in class GridReader
Returns:
the width (in pixels) of the read raster

getDataLocationId

public String getDataLocationId()
Specified by:
getDataLocationId in interface RasterReader
Overrides:
getDataLocationId in class GridFileReader
Returns:
a String which identifies this reader for used the data source, for example the file name, or an url.

lastReadAccess

public long lastReadAccess()
Return the current time millis of the last read action. This method is needed for caching.

Returns:
the System.currentTimeMillis() of the last read operation.

currentApproxMemory

public long currentApproxMemory()
Returns:
the current amount of memory this cached reader has on byte buffers.

dispose

public void dispose()
Description copied from interface: RasterReader
Signals the reader that it should try to dispose all in memory data.

Specified by:
dispose in interface RasterReader
Overrides:
dispose in class GridFileReader

dispose

public long dispose(boolean memoryBuffersAsWell)
Causes the cachefile to be written (if existing) and the memory buffers to be set to null.

Parameters:
memoryBuffersAsWell - if true the memorybuffers (the ones which don't have rasterfiles to back them up) will be deleted as well.
Returns:
the amount of freed memory.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

flush

public void flush()
Writes all current in memory byte buffers to the cache file (if existing).


deegree-core-3.0-pre-nightly (2010/03/05 00:01) - official

an open source project founded by lat/lon, Bonn, Germany.
For more information visit: http://www.deegree.org

]]>