public interface ArrayAccess extends ArrayDescription
ChunkStepper
class is provided as a convenience to assist with this sort of
processing.
The accessor maintains an offset position which determines the starting
position of the next read/write. This may be modified by the
setOffset or setPosition methods. The mapping between offset values
and position vectors is determined by the pixel ordering scheme
of this ArrayAccess (as determined by its OrderedNDShape
).
Not all methods will work on a given accessor, depending on what it is capable of; if the isRandom method returns false then the offset may not be set to a position before its current position; if isReadable returns false then the read and readTile methods will fail; and if isWritable returns false then the write and writeTile methods will fail. In each of these cases the illegal accesses will result in an UnsupportedOperationException.
If the read or write methods result in an IOException this will have the side effect of closing this accessor for further access (since under these circumstances the current offset may not be known).
Modifier and Type | Method and Description |
---|---|
void |
close()
Shuts down this accessor for further data access.
|
Object |
getMapped()
Returns a single primitive array holding all the data of this array.
|
long |
getOffset()
Returns the current offset into the array for read/write.
|
long[] |
getPosition()
Returns the coordinates at which the next read/write will occur.
|
boolean |
isMapped()
Indicates whether mapped access is available.
|
void |
read(Object buffer,
int start,
int size)
Reads a number of pixels from the current offset into a specified
part of a supplied primitive array.
|
void |
readTile(Object buffer,
NDShape tileShape)
Reads a tile of pixels into a supplied primitive array.
|
void |
setOffset(long off)
Sets the offset into the array for the next read/write to occur.
|
void |
setPosition(long[] pos)
Sets the coordinates for the next read/write to occur.
|
void |
write(Object buffer,
int start,
int size)
Writes a number of pixels starting at the current offset from a
specified part of a supplied primitive array.
|
void |
writeTile(Object buffer,
NDShape tileShape)
Writes a tile of pixels from a supplied primitive array.
|
getBadHandler, getShape, getType, isRandom, isReadable, isWritable
long getOffset()
void setOffset(long off) throws IOException
off
- the position at which the next read/write will startIOException
- if some unexpected I/O error occursIndexOutOfBoundsException
- if off<0 or off>=npixelIllegalStateException
- if this accessor has been closedUnsupportedOperationException
- if an attempt is made to set
the offset to a value lower than its current one,
and random access is not available for this accessorlong[] getPosition()
void setPosition(long[] pos) throws IOException
pos
- an N-element array giving the coordinates for the next
read/writeIOException
- if some unexpected I/O error occursIndexOutOfBoundsException
- if pos is outside the arrayIllegalStateException
- if this accessor has been closedUnsupportedOperationException
- if an attempt is made to set
the offset to a value lower than its current one,
and random access is not availablevoid read(Object buffer, int start, int size) throws IOException
An IOException during the read will have the effect of closing this accessor for further access.
buffer
- an array of the appropriate primitive type for this
accessor into whose elements
start..start+size
the next size
pixels will be readstart
- the starting offset into buffer into which the
pixels should be readsize
- the number of pixels to read (also the amount by
which the current offset will be incremented)IOException
- if there is an I/O errorUnsupportedOperationException
- if this accessor is not
readable (isReadable returns false)IllegalStateException
- if this accessor has been closedIllegalArgumentException
- if buffer is not an array of
primitives with type matching the type of this accessor,
or if it has less than start+size elementsvoid readTile(Object buffer, NDShape tileShape) throws IOException
The current offset will be updated to the point after the last pixel in the intersection between the tile and this accessor.
It is possible to read a tile when random access is not available, but only if the first pixel in the requested tile is ahead of the current offset.
An IOException during the read will have the effect of closing this accessor for further access.
buffer
- an array of the appropriate primitive type for this
accessor and at least as long as the number of
pixels in tileShapetileShape
- an NDShape object specifying the shape of the tile
to be readIOException
- if there is an I/O errorUnsupportedOperationException
- if this object is not readable (isReadable returns false)
or if it would be necessary to read a part of the data
earlier than the current offset and random access is not
availableIllegalArgumentException
- if buffer is not an array of the
right primitive type or has too few elementsIllegalStateException
- if this accessor has been closedvoid write(Object buffer, int start, int size) throws IOException
If an IOException occurs during the read, this will have the additional effect of closing this accessor for further access.
buffer
- an array of the appropriate primitive type for this
NDArray whose elements start..start+size
will be written outstart
- the starting point in buffer from which pixels
will be writtensize
- the number of pixels to write (also the amount by
which the current offset will be incremented)IOException
- if there is an I/O errorUnsupportedOperationException
- if this accessor is not
writable (isWritable returns false)IllegalStateException
- if this accessor has been closedIllegalArgumentException
- if buffer is not an array of
primitives with type matching the type of this accessor,
or if it has less than start+size elementsvoid writeTile(Object buffer, NDShape tileShape) throws IOException
The current offset will be updated to the point after the last pixel in the intersection between the tile and this accessor.
It is possible to read a tile when random access is not available, but only if the first pixel in the requested tile is ahead of the current offset.
If an IOException occurs during the write, this will have the additional effect of closing this accessor for further access.
buffer
- an array of the appropriate primitive type for this
NDArray and at least as long as the number of
pixels in tileShape (elements after this limit
will be ignored)tileShape
- an NDShape object specifying the shape of the tile
to be writtenIOException
- if there is an I/O errorUnsupportedOperationException
- if this accessor is not writable (isWritable returns false)
or if it would be necessary to write a part of the data
earlier than the current offset and random access is not
availableIllegalArgumentException
- if buffer is not an array of the
right primitive type or has too few elementsIllegalStateException
- if this accessor has been closedboolean isMapped()
Object getMapped()
The method will fail unless isMapped returns true.
UnsupportedOperationException
- if mapped access is not
availableIllegalStateException
- if this accessor has been closedvoid close() throws IOException
close
the offset
will have an illegal value
and calls to any read, write or position setting methods
will fail with an IllegalStateException.
A close
should always
be called on an ArrayAccess when it is finished with.
In the case of a readable
object it enables release of associated resources beyond those taken
care of by the garbage collector, and in the case of writable
object it may also be required to ensure that data is actually
flushed to the underlying data storage.
This method may harmlessly be called on an accessor which has already
been closed.IOException
- if there is an I/O errorCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.