Class HyperRectangleReader
java.lang.Object
org.apache.sis.internal.storage.io.HyperRectangleReader
- Direct Known Subclasses:
RawRasterReader
Helper methods for reading a rectangular area, a cube or a hyper-cube from a channel.
The data can be stored in an existing array, or a new array can be created.
This class does not handle compression; it is rather designed for efficient reading of uncompressed data.
It tries to read the largest possible contiguous blocks of data with single
ReadableByteChannel.read(ByteBuffer) and
ByteBuffer.get(byte[], int, int) method calls.
This reader supports subsampling in any dimension. However, subsampling in the first dimension (the one with fastest varying index) is generally not efficient because it forces a large amount of seek operations. This class makes no special case for making that specific subsampling faster. It is generally not worth because subsampling in the first dimension is a special case anyway. It is the "dimension" of bands in an image using the pixel interleaved sample model, so the caller often needs to process subsampling in the first dimension in a different way than other dimensions anyway.
- Since:
- 0.7
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longTheinputposition of the first sample (ignoring sub-area and subsampling).private final DataTransferThe channel from which to read the values, together with a buffer for transferring data. -
Constructor Summary
ConstructorsConstructorDescriptionHyperRectangleReader(byte dataType, ChannelDataInput input) Creates a new reader for the given input.HyperRectangleReader(String filename, Buffer data) Creates a new reader for the data in an existing buffer. -
Method Summary
Modifier and TypeMethodDescriptionfinal Stringfilename()Returns a file identifier for error messages or debugging purpose.final longReturns theinputposition of the first sample (ignoring sub-area and subsampling).final ObjectReads data in the given region.private ObjectImplementation ofread(Region)and#readAsBuffer(Region).final BufferreadAsBuffer(Region region, int capacity) Reads data in the given region as a buffer.final intReturns the number of bytes in each value to be read.final voidsetOrigin(long p) Sets theinputposition of the first sample (ignoring sub-area and subsampling).
-
Field Details
-
reader
The channel from which to read the values, together with a buffer for transferring data. -
origin
private long originTheinputposition of the first sample (ignoring sub-area and subsampling). This is initially theoriginargument given to the constructor, copied verbatim.- See Also:
-
-
Constructor Details
-
HyperRectangleReader
Creates a new reader for the given input.- Parameters:
dataType- the type of elements to read, as one of the constants defined inNumbers.input- the channel from which to read the values, together with a buffer for transferring data.- Throws:
DataStoreContentException- if the givendataTypeis not one of the supported values.
-
HyperRectangleReader
Creates a new reader for the data in an existing buffer. The data will be read from the current buffer position to the buffer limit.- Parameters:
filename- a data source name, for error messages or debugging purpose.data- a buffer containing the data to read.- Throws:
IOException- should never happen.
-
-
Method Details
-
filename
Returns a file identifier for error messages or debugging purpose.- Returns:
- the file identifier.
-
sampleSize
public final int sampleSize()Returns the number of bytes in each value to be read.- Returns:
- number of bytes per value.
-
getOrigin
public final long getOrigin()Returns theinputposition of the first sample (ignoring sub-area and subsampling). Default value is 0.- Returns:
- the
inputposition of the first sample (ignoring sub-area and subsampling).
-
setOrigin
public final void setOrigin(long p) Sets theinputposition of the first sample (ignoring sub-area and subsampling).- Parameters:
p- the newinputposition of the first sample (ignoring sub-area and subsampling).
-
read
Reads data in the given region. It is caller's responsibility to ensure that theRegionobject has been created with asizeargument equals to this hyper-rectangle size.- Parameters:
region- the sub-area to read and the subsampling to use.- Returns:
- the data in an array of primitive type.
- Throws:
IOException- if an error occurred while transferring data from the channel.ArithmeticException- if the region to read is too large or too far from origin.
-
readAsBuffer
Reads data in the given region as a buffer. This method performs the same work thanread(Region)except that the array is wrapped in a heap buffer. Thecapacityargument is the minimal length of the array to allocate. The actual length of data read will be the limit of the returned buffer.- Parameters:
region- the sub-area to read and the subsampling to use.capacity- minimal length of the array to allocate, or 0 for automatic.- Returns:
- the data in a buffer backed by an array on the heap.
- Throws:
IOException- if an error occurred while transferring data from the channel.ArithmeticException- if the region to read is too large or too far from origin.
-
read
Implementation ofread(Region)and#readAsBuffer(Region).- Parameters:
region- the sub-area to read and the subsampling to use.capacity- minimal length of the array to allocate, or 0 for automatic.asBuffer-truefor wrapping the array in aBuffer.- Returns:
- the data as an array or wrapped in a buffer, depending on
asBuffervalue. - Throws:
IOException
-