public class DefaultArrayAccess extends DefaultArrayDescription implements ArrayAccess
Exemplifies the Bridge Pattern.
arrayDims, arrayHandler, arrayIsRandom, arrayIsReadable, arrayIsWritable, arrayNdim, arrayNpix, arrayOrder, arrayOrigin, arrayShape, arrayType
Constructor and Description |
---|
DefaultArrayAccess(ArrayDescription adesc,
AccessImpl impl,
Object mappedArray)
Constructs an ArrayAccess object from a description of the array's
characteristics and a basic implementation of pixel access
functionality.
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkOpen() |
void |
close()
Shuts down this accessor for further data access.
|
protected void |
doClose() |
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 tile)
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.
|
String |
toString() |
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 tile)
Writes a tile of pixels from a supplied primitive array.
|
getBadHandler, getShape, getType, isRandom, isReadable, isWritable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getBadHandler, getShape, getType, isRandom, isReadable, isWritable
public DefaultArrayAccess(ArrayDescription adesc, AccessImpl impl, Object mappedArray)
adesc
- array characteristics descriptionimpl
- array access service provider, available for
exclusive use by this objectmappedArray
- a java primitve array containing all the pixel
data of the accessed array. May be null if
mapped access is not providedpublic long getOffset()
ArrayAccess
getOffset
in interface ArrayAccess
public void setOffset(long off) throws IOException
ArrayAccess
setOffset
in interface ArrayAccess
off
- the position at which the next read/write will startIOException
- if some unexpected I/O error occurspublic long[] getPosition()
ArrayAccess
getPosition
in interface ArrayAccess
public void setPosition(long[] pos) throws IOException
ArrayAccess
setPosition
in interface ArrayAccess
pos
- an N-element array giving the coordinates for the next
read/writeIOException
- if some unexpected I/O error occurspublic void read(Object buffer, int start, int size) throws IOException
ArrayAccess
An IOException during the read will have the effect of closing this accessor for further access.
read
in interface ArrayAccess
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 errorpublic void readTile(Object buffer, NDShape tile) throws IOException
ArrayAccess
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.
readTile
in interface ArrayAccess
buffer
- an array of the appropriate primitive type for this
accessor and at least as long as the number of
pixels in tileShapetile
- an NDShape object specifying the shape of the tile
to be readIOException
- if there is an I/O errorpublic void write(Object buffer, int start, int size) throws IOException
ArrayAccess
If an IOException occurs during the read, this will have the additional effect of closing this accessor for further access.
write
in interface ArrayAccess
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 errorpublic void writeTile(Object buffer, NDShape tile) throws IOException
ArrayAccess
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.
writeTile
in interface ArrayAccess
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)tile
- an NDShape object specifying the shape of the tile
to be writtenIOException
- if there is an I/O errorpublic boolean isMapped()
ArrayAccess
isMapped
in interface ArrayAccess
public Object getMapped()
ArrayAccess
The method will fail unless isMapped returns true.
getMapped
in interface ArrayAccess
public void close() throws IOException
ArrayAccess
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.close
in interface ArrayAccess
IOException
- if there is an I/O errorprotected void doClose()
protected void checkOpen()
Copyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.