Class DefaultArrayAccess
- All Implemented Interfaces:
ArrayAccess,ArrayDescription
Exemplifies the Bridge Pattern.
- Author:
- Mark Taylor (Starlink)
-
Field Summary
Fields inherited from class uk.ac.starlink.array.DefaultArrayDescription
arrayDims, arrayHandler, arrayIsRandom, arrayIsReadable, arrayIsWritable, arrayNdim, arrayNpix, arrayOrder, arrayOrigin, arrayShape, arrayType -
Constructor Summary
ConstructorsConstructorDescriptionDefaultArrayAccess(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. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()Shuts down this accessor for further data access.protected voiddoClose()Returns a single primitive array holding all the data of this array.longReturns the current offset into the array for read/write.long[]Returns the coordinates at which the next read/write will occur.booleanisMapped()Indicates whether mapped access is available.voidReads a number of pixels from the current offset into a specified part of a supplied primitive array.voidReads a tile of pixels into a supplied primitive array.voidsetOffset(long off) Sets the offset into the array for the next read/write to occur.voidsetPosition(long[] pos) Sets the coordinates for the next read/write to occur.toString()voidWrites a number of pixels starting at the current offset from a specified part of a supplied primitive array.voidWrites a tile of pixels from a supplied primitive array.Methods inherited from class uk.ac.starlink.array.DefaultArrayDescription
getBadHandler, getShape, getType, isRandom, isReadable, isWritableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface uk.ac.starlink.array.ArrayDescription
getBadHandler, getShape, getType, isRandom, isReadable, isWritable
-
Constructor Details
-
DefaultArrayAccess
Constructs an ArrayAccess object from a description of the array's characteristics and a basic implementation of pixel access functionality.- Parameters:
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 provided
-
-
Method Details
-
getOffset
public long getOffset()Description copied from interface:ArrayAccessReturns the current offset into the array for read/write.- Specified by:
getOffsetin interfaceArrayAccess- Returns:
- the index of the next element to be read/written
-
setOffset
Description copied from interface:ArrayAccessSets the offset into the array for the next read/write to occur. Attempting to set the offset to a lower value than its current one will fail if random access is not available (isRandom is false).- Specified by:
setOffsetin interfaceArrayAccess- Parameters:
off- the position at which the next read/write will start- Throws:
IOException- if some unexpected I/O error occurs
-
getPosition
public long[] getPosition()Description copied from interface:ArrayAccessReturns the coordinates at which the next read/write will occur.- Specified by:
getPositionin interfaceArrayAccess- Returns:
- an N-element array giving the coordinates of the next read/write
-
setPosition
Description copied from interface:ArrayAccessSets the coordinates for the next read/write to occur. Attempting to set the coordinates so that the new offset corresponds to a lower value than its current one will fail if random access is not available (isRandom returns false).- Specified by:
setPositionin interfaceArrayAccess- Parameters:
pos- an N-element array giving the coordinates for the next read/write- Throws:
IOException- if some unexpected I/O error occurs
-
read
Description copied from interface:ArrayAccessReads a number of pixels from the current offset into a specified part of a supplied primitive array. The current offset will be updated accordingly (to the point after the read pixels).An IOException during the read will have the effect of closing this accessor for further access.
- Specified by:
readin interfaceArrayAccess- Parameters:
buffer- an array of the appropriate primitive type for this accessor into whose elementsstart..start+sizethe nextsizepixels 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)- Throws:
IOException- if there is an I/O error
-
readTile
Description copied from interface:ArrayAccessReads a tile of pixels into a supplied primitive array. A tile is an N-dimensional hypercuboid specified by an NDShape object. The pixels are read into a given array in the order implied by the ordering scheme of this object. The specified tile must have the same dimensionality as this accessor, but need not lie wholly or partially within its bounds -- pixels outside the intersection will be given the bad value.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.
- Specified by:
readTilein interfaceArrayAccess- Parameters:
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 read- Throws:
IOException- if there is an I/O error
-
write
Description copied from interface:ArrayAccessWrites a number of pixels starting at the current offset from a specified part of a supplied primitive array. The current offset will be updated accordingly (to the point after the last write).If an IOException occurs during the read, this will have the additional effect of closing this accessor for further access.
- Specified by:
writein interfaceArrayAccess- Parameters:
buffer- an array of the appropriate primitive type for this NDArray whose elementsstart..start+sizewill 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)- Throws:
IOException- if there is an I/O error
-
writeTile
Description copied from interface:ArrayAccessWrites a tile of pixels from a supplied primitive array. A tile is an N-dimensional hypercuboid specified by an NDShape object. The ordering of pixels in the array is implied by the ordering scheme of this object. The specified tile must have the same dimensionality as this accessor, but need not lie wholly or partially within its bounds -- pixels outside the intersection will simply be ignored.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.
- Specified by:
writeTilein interfaceArrayAccess- Parameters:
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 written- Throws:
IOException- if there is an I/O error
-
isMapped
public boolean isMapped()Description copied from interface:ArrayAccessIndicates whether mapped access is available. If true, the getMapped method will return a reference to the java primitive array containing all the pixels of this NDArray. The return value must not change over the lifetime of this object.- Specified by:
isMappedin interfaceArrayAccess- Returns:
- true if mapped access is possible
-
getMapped
Description copied from interface:ArrayAccessReturns a single primitive array holding all the data of this array. Calling this method does not do significant work, but returns a reference to an existing mapped array. Access to the array data using this method, if available, will be more efficient than by using the read/write methods. In the case of a writable accessor, making changes to the returned primitive array will result in changes to the accessor pixel data. In the case of an accessor which is not writable, the effect of making changes to the returned array is undefined; in particular it may result in an exception.The method will fail unless isMapped returns true.
- Specified by:
getMappedin interfaceArrayAccess- Returns:
- a primitive array, of type implied by the Type of this object, containing all the pixels of this array, in its natural ordering
-
close
Description copied from interface:ArrayAccessShuts down this accessor for further data access. Following a call toclosethe offset will have an illegal value and calls to any read, write or position setting methods will fail with an IllegalStateException. Acloseshould 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.- Specified by:
closein interfaceArrayAccess- Throws:
IOException- if there is an I/O error
-
doClose
protected void doClose() -
checkOpen
protected void checkOpen() -
toString
-