ilog.views.maps.raster
Class IlvRasterMappedBuffer

java.lang.Object
  extended by ilog.views.maps.raster.IlvRasterMappedBuffer
All Implemented Interfaces:
IlvPersistentObject

public class IlvRasterMappedBuffer
extends Object
implements IlvPersistentObject

Class managing the raster data for readers. It uses temporary files to store the rasters when they are not needed. The constructors provide a setting to put the pixels directly in the temporary file, assuming that the pixels will not be used immediately after the raster image is created. This is convenient for map readers that create a lot of raster image source.

Since:
JViews 7.5

Nested Class Summary
static interface IlvRasterMappedBuffer.JITDataLoader
          Class responsible for loading raster data when an IlvRasterTileLoader loads a tile whose buffer is empty (0 bytes).
 
Field Summary
static int BYTE_RASTER
          When the the data type attribute is set to this value, it means that the raster is coded with bytes.
static int INT_RASTER
          When the the data type attribute is set to this value, it means that the raster is coded with integers.
protected  int memoryManagement
          Timer releasing the raster from the memory 1 sec after the unloadtile to give time for a loadTile event to change the resolution.
static int SHORT_RASTER
          When the the data type attribute is set to this value, it means that the raster is coded with short.
static int USE_MAP
          Indicates a raster mapped buffer storing pixel information on disk mapped memory.
static int USE_MEMORY
          Indicates a raster mapped buffer storing pixel information in memory.
 
Constructor Summary
IlvRasterMappedBuffer(IlvInputStream stream)
          Reads the rasterinfo from the specified input stream.
IlvRasterMappedBuffer(String sourceName, byte[] pixels)
          Constructor.
IlvRasterMappedBuffer(String sourceName, int[] pixels)
          Constructor.
IlvRasterMappedBuffer(String sourceName, int type, int size)
          Creates a mapped buffer from a file with the correct content.
IlvRasterMappedBuffer(String sourceName, int size, String fName, int rasterDataType)
          Creates a raster mapped buffer without creating a temporary file.
IlvRasterMappedBuffer(String sourceName, int size, URL url, int rasterDataType)
          Creates a raster mapped buffer from an url.
IlvRasterMappedBuffer(String sourceName, short[] pixels)
          Constructor.
 
Method Summary
 void clear()
          Clear the memory or the files supporting the raster data.
 void closeMap()
          Closes any file related resource used by this IlvRasterMappedBuffer (RandomAccessFile, FileChannel as well as MappedByteBuffer.
protected  void finalize()
          Clear the raster image source on finalization.
 long getAccessChannelPosition()
          Returns the accessChannelPosition.
 int getArraySize()
          Returns the array Size.
 int getBytePixel(int index, int noDataValue)
          Retrieve the information from the raster data.
static int getDefaultMemoryPolicy()
          Returns the default memory management policy that will be used when
 int getIntPixel(int index, int noDataValue)
          Retrieve the information from the raster data.
 IlvRasterMappedBuffer.JITDataLoader getLoader()
          Returns the optional Just-In-Time data loader for this buffer.
 int getRasterDataType()
          Indicates the kind of data supported.
protected  void initMemoryManagement()
          Method that initializes the memory management for this buffer.
 boolean isSwapBytes()
          Returns whether bytes have to be swapped.
 void putBytePixel(int index, byte value)
          Sets the pixel with the value provided.
 void putIntPixel(int index, int value)
          Sets the pixel with the value provided.
 void remap(RandomAccessFile raf, long position)
          Deprecated.  
 void remap(String filename, long position)
          Changes the underlying mapped byte buffer use by this class
 void setBytes(byte[] pixels)
          Changes the pixel array of the original image.
static void setDefaultMemoryPolicy(int defaultMemoryPolicy)
          Indicates the default memory management policy that will be used when creating an IlvRasterMappedBuffer.
 void setInts(int[] pixels)
          Changes the pixel array of the original image.
 void setLoader(IlvRasterMappedBuffer.JITDataLoader loader)
          Sets the optional Just-In-Time data loader for this buffer.
 void setShorts(short[] pixels)
          Changes the pixel array of the original image
 void setSwapBytes(boolean swap)
          Indicate if bytes have to be swapped.Default is false.
 void write(IlvOutputStream out)
          Writes the attributes of a persistent object.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_RASTER

public static final int BYTE_RASTER
When the the data type attribute is set to this value, it means that the raster is coded with bytes.

See Also:
Constant Field Values

INT_RASTER

public static final int INT_RASTER
When the the data type attribute is set to this value, it means that the raster is coded with integers.

See Also:
Constant Field Values

SHORT_RASTER

public static final int SHORT_RASTER
When the the data type attribute is set to this value, it means that the raster is coded with short.

See Also:
Constant Field Values

USE_MAP

public static final int USE_MAP
Indicates a raster mapped buffer storing pixel information on disk mapped memory.

See Also:
Constant Field Values

USE_MEMORY

public static final int USE_MEMORY
Indicates a raster mapped buffer storing pixel information in memory.

See Also:
Constant Field Values

memoryManagement

protected int memoryManagement
Timer releasing the raster from the memory 1 sec after the unloadtile to give time for a loadTile event to change the resolution. private transient Timer freeMemoryTimer = null;

Constructor Detail

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(IlvInputStream stream)
                      throws IlvReadFileException
Reads the rasterinfo from the specified input stream.

Parameters:
stream - The input stream.
Throws:
IlvReadFileException - if an error occurs while reading the data.

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(String sourceName,
                             byte[] pixels)
Constructor. Manages raster data and the temporary file to free the memory from the raster data when it is not used. The source name is used to generate a unique temporary file name.

Parameters:
sourceName - The identifier of the raster producer.
pixels - The pixel array of the original image.

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(String sourceName,
                             short[] pixels)
Constructor. Manages raster data and the temporary file to free the memory from the raster data when it is not used. The source name is used to generate a unique temporary file name.

Parameters:
sourceName - The identifier of the raster producer.
pixels - The pixel array of the original image.

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(String sourceName,
                             int type,
                             int size)
Creates a mapped buffer from a file with the correct content.

Parameters:
sourceName - Name of the buffer.
type - Type of buffer (SHORT_RASTER,INT_RASTER, BYTE_RASTER).
size - Number of elements in the array.

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(String sourceName,
                             int size,
                             String fName,
                             int rasterDataType)
Creates a raster mapped buffer without creating a temporary file.

Parameters:
sourceName - The identifier of the raster producer.
size - The number of elements in the data.
fName - The file to read (in internal format).
rasterDataType - The type of data.

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(String sourceName,
                             int size,
                             URL url,
                             int rasterDataType)
Creates a raster mapped buffer from an url.

Parameters:
sourceName - The identifier of the raster producer.
size - The number of elements in the data.
url - The URL to read (in internal format).
rasterDataType - The type of data.
Since:
JViews 7.5

IlvRasterMappedBuffer

public IlvRasterMappedBuffer(String sourceName,
                             int[] pixels)
Constructor. Manages raster data and the temporary file to free the memory from the raster data when it is not used. The source name is used to generate a unique temporary file name.

Parameters:
sourceName - The identifier of the raster producer.
pixels - The pixel array of the original image.
Method Detail

setDefaultMemoryPolicy

public static void setDefaultMemoryPolicy(int defaultMemoryPolicy)
Indicates the default memory management policy that will be used when creating an IlvRasterMappedBuffer.

Parameters:
defaultMemoryPolicy - either USE_MAPor USE_MEMORY

getDefaultMemoryPolicy

public static int getDefaultMemoryPolicy()
Returns the default memory management policy that will be used when

Returns:
Returns the default memory management policy that will be used when creating an IlvRasterMappedBuffer.
See Also:
setDefaultMemoryPolicy(int)

setBytes

public void setBytes(byte[] pixels)
Changes the pixel array of the original image.

Parameters:
pixels - The pixel array of the original image.

initMemoryManagement

protected void initMemoryManagement()
Method that initializes the memory management for this buffer. It uses the default memory policy, unless the number of bytes is under 1000, for which it uses USE_MEMORY.

See Also:
setDefaultMemoryPolicy(int)

setShorts

public void setShorts(short[] pixels)
Changes the pixel array of the original image

Parameters:
pixels - The pixel array of the original image.

setInts

public void setInts(int[] pixels)
Changes the pixel array of the original image.

Parameters:
pixels - The pixel array of the original image.

getArraySize

public int getArraySize()
Returns the array Size.

Returns:
Returns the array Size.

clear

public void clear()
Clear the memory or the files supporting the raster data.


closeMap

public void closeMap()
Closes any file related resource used by this IlvRasterMappedBuffer (RandomAccessFile, FileChannel as well as MappedByteBuffer.


getBytePixel

public int getBytePixel(int index,
                        int noDataValue)
Retrieve the information from the raster data. If the raster has been freed from memory, it is reloaded from the temporary file.

Parameters:
index - The index of the pixel to retrieve from the raster data.
noDataValue - Value to return when the index is out of bounds.
Returns:
The pixel of the original image at the given position.

remap

public void remap(RandomAccessFile raf,
                  long position)
Deprecated. 

Changes the underlying mapped byte buffer use by this class

Parameters:
raf - a RandomAccessFile on a file containing raster data
position - the buffer start position on the file

remap

public void remap(String filename,
                  long position)
           throws FileNotFoundException
Changes the underlying mapped byte buffer use by this class

Parameters:
filename - the name of a file containing raster data
position - the buffer start position on the file
Throws:
FileNotFoundException
Since:
JViews 7.5

isSwapBytes

public boolean isSwapBytes()
Returns whether bytes have to be swapped.

Returns:
Returns whether bytes have to be swapped.

setSwapBytes

public void setSwapBytes(boolean swap)
Indicate if bytes have to be swapped.Default is false.

Parameters:
swap - The swap to set.

getIntPixel

public int getIntPixel(int index,
                       int noDataValue)
Retrieve the information from the raster data. If the raster has been freed from memory, it is reloaded from the temporary file.

Parameters:
index - The index of the pixel to retrieve from the raster data.
noDataValue - Value to return when index is out of bounds.
Returns:
The pixel of the original image at the given position.

getRasterDataType

public int getRasterDataType()
Indicates the kind of data supported.

Returns:
either BYTE_RASTERor INT_RASTERdepending on the constructor that was used.

write

public void write(IlvOutputStream out)
           throws IOException
Writes the attributes of a persistent object.

Specified by:
write in interface IlvPersistentObject
Parameters:
out - the output stream
Throws:
IOException - thrown when an exception occurs during the write operation for this object.
See Also:
IlvPersistentObject.write(ilog.views.io.IlvOutputStream)

finalize

protected void finalize()
                 throws Throwable
Clear the raster image source on finalization.

Overrides:
finalize in class Object
Throws:
Throwable
See Also:
Object.finalize(), clear()

putIntPixel

public void putIntPixel(int index,
                        int value)
                 throws IOException
Sets the pixel with the value provided.

Parameters:
index - Index of the pixel in the single dimension array.
value - Value of the pixel.
Throws:
IOException - in case of error writing the value on the disc.

putBytePixel

public void putBytePixel(int index,
                         byte value)
                  throws IOException
Sets the pixel with the value provided.

Parameters:
index - Index of the pixel in the single dimension array.
value - Value of the pixel.
Throws:
IOException - in case of error writing the value on the disc.

getAccessChannelPosition

public long getAccessChannelPosition()
Returns the accessChannelPosition.

Returns:
Returns the accessChannelPosition.

setLoader

public void setLoader(IlvRasterMappedBuffer.JITDataLoader loader)
Sets the optional Just-In-Time data loader for this buffer. Default is null - that means that the data is supposedly already loaded when tiles are first loaded.

Parameters:
loader -

getLoader

public IlvRasterMappedBuffer.JITDataLoader getLoader()
Returns the optional Just-In-Time data loader for this buffer.

Returns:
Returns the optional Just-In-Time data loader for this buffer.


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.