Package loci.common
Interface IRandomAccess
- All Superinterfaces:
DataInput,DataOutput
- All Known Implementing Classes:
AbstractNIOHandle,ByteArrayHandle,BZip2Handle,FileHandle,GZipHandle,NIOFileHandle,S3Handle,StreamHandle,URLHandle,ZipHandle
Interface for random access into structures (e.g., files or arrays).
- Author:
- Curtis Rueden ctrueden at wisc.edu
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this random access stream and releases any system resources associated with the stream.booleanexists()Returns whether this refers to a valid objectlongReturns the current offset in this stream.getOrder()Returns the current order (endianness) of the stream.longlength()Returns the length of this stream.intread(byte[] b) Reads up to b.length bytes of data from this stream into an array of bytes.intread(byte[] b, int off, int len) Reads up to len bytes of data from this stream into an array of bytes.intread(ByteBuffer buffer) Reads up to buffer.capacity() bytes of data from this stream into a ByteBuffer.intread(ByteBuffer buffer, int offset, int len) Reads up to len bytes of data from this stream into a ByteBuffer.voidseek(long pos) Sets the stream pointer offset, measured from the beginning of this stream, at which the next read or write occurs.voidSets the byte order (endianness) of the stream.longskipBytes(long n) Alongvariant ofskipBytes(int).voidwrite(ByteBuffer buf) Writes up to buffer.capacity() bytes of data from the given ByteBuffer to this stream.voidwrite(ByteBuffer buf, int off, int len) Writes up to len bytes of data from the given ByteBuffer to this stream.Methods inherited from interface java.io.DataInput
readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, skipBytesMethods inherited from interface java.io.DataOutput
write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
Method Details
-
close
Closes this random access stream and releases any system resources associated with the stream.- Throws:
IOException- if the underlying stream(s) could not be closed
-
getFilePointer
Returns the current offset in this stream.- Returns:
- the current byte offset within the file; expected to be non-negative and less than the value of #length()
- Throws:
IOException- if the offset cannot be retrieved
-
exists
Returns whether this refers to a valid object- Returns:
- true if this refers to a valid object
- Throws:
IOException- if unable to determine whether the object is valid
-
length
Returns the length of this stream.- Returns:
- the length in bytes of the stream
- Throws:
IOException- if the length cannot be retrieved
-
getOrder
ByteOrder getOrder()Returns the current order (endianness) of the stream.- Returns:
- See above.
-
setOrder
Sets the byte order (endianness) of the stream.- Parameters:
order- Order to set.
-
read
Reads up to b.length bytes of data from this stream into an array of bytes.- Parameters:
b- the array to fill from this stream- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException- if reading is not possible
-
read
Reads up to len bytes of data from this stream into an array of bytes.- Parameters:
b- the array to fill from this streamoff- the offset inbfrom which to start filling; expected to be non-negative and no greater thanb.length - lenlen- the number of bytes to read; expected to be positive and no greater thanb.length - offset- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException- if reading is not possible
-
read
Reads up to buffer.capacity() bytes of data from this stream into a ByteBuffer.- Parameters:
buffer- the ByteBuffer to fill from this stream- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException- if reading is not possible
-
read
Reads up to len bytes of data from this stream into a ByteBuffer.- Parameters:
buffer- the ByteBuffer to fill from this streamoffset- the offset inbfrom which to start filling; expected to be non-negative and no greater thanbuffer.capacity() - lenlen- the number of bytes to read; expected to be positive and no greater thanbuffer.capacity() - offset- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException- if reading is not possible
-
seek
Sets the stream pointer offset, measured from the beginning of this stream, at which the next read or write occurs.- Parameters:
pos- new byte offset (pointer) in the current stream. Unless otherwise noted, may be larger or smaller than the current pointer, but must be non-negative and less than the value of #length()- Throws:
IOException- ifposis invalid or the seek fails- See Also:
-
skipBytes
Alongvariant ofskipBytes(int).- Parameters:
n- the number of bytes to skip- Returns:
- the number of bytes skipped
- Throws:
IOException- if the operation failed
-
write
Writes up to buffer.capacity() bytes of data from the given ByteBuffer to this stream.- Parameters:
buf- the ByteBuffer containing bytes to write to this stream- Throws:
IOException- if writing is not possible
-
write
Writes up to len bytes of data from the given ByteBuffer to this stream.- Parameters:
buf- the ByteBuffer containing bytes to write to this streamoff- the offset inbfrom which to start writing; expected to be non-negative and no greater thanbuf.capacity() - lenlen- the number of bytes to write; expected to be positive and no greater thanbuf.capacity() - offset- Throws:
IOException- if writing is not possible
-