Package loci.common
Interface IRandomAccess
-
- All Superinterfaces:
DataInput
,DataOutput
- All Known Implementing Classes:
AbstractNIOHandle
,ByteArrayHandle
,BZip2Handle
,FileHandle
,GZipHandle
,NIOFileHandle
,S3Handle
,StreamHandle
,URLHandle
,ZipHandle
public interface IRandomAccess extends DataInput, DataOutput
Interface for random access into structures (e.g., files or arrays).- Author:
- Curtis Rueden ctrueden at wisc.edu
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
Closes this random access stream and releases any system resources associated with the stream.boolean
exists()
Returns whether this refers to a valid objectlong
getFilePointer()
Returns the current offset in this stream.ByteOrder
getOrder()
Returns the current order (endianness) of the stream.long
length()
Returns the length of this stream.int
read(byte[] b)
Reads up to b.length bytes of data from this stream into an array of bytes.int
read(byte[] b, int off, int len)
Reads up to len bytes of data from this stream into an array of bytes.int
read(ByteBuffer buffer)
Reads up to buffer.capacity() bytes of data from this stream into a ByteBuffer.int
read(ByteBuffer buffer, int offset, int len)
Reads up to len bytes of data from this stream into a ByteBuffer.void
seek(long pos)
Sets the stream pointer offset, measured from the beginning of this stream, at which the next read or write occurs.void
setOrder(ByteOrder order)
Sets the byte order (endianness) of the stream.long
skipBytes(long n)
Along
variant ofDataInput.skipBytes(int)
.void
write(ByteBuffer buf)
Writes up to buffer.capacity() bytes of data from the given ByteBuffer to this stream.void
write(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, skipBytes
-
Methods inherited from interface java.io.DataOutput
write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
-
-
-
-
Method Detail
-
close
void close() throws IOException
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
long getFilePointer() throws IOException
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
boolean exists() throws IOException
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
long length() throws IOException
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
void setOrder(ByteOrder order)
Sets the byte order (endianness) of the stream.- Parameters:
order
- Order to set.
-
read
int read(byte[] b) throws IOException
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
int read(byte[] b, int off, int len) throws IOException
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 inb
from which to start filling; expected to be non-negative and no greater thanb.length - len
len
- 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
int read(ByteBuffer buffer) throws IOException
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
int read(ByteBuffer buffer, int offset, int len) throws IOException
Reads up to len bytes of data from this stream into a ByteBuffer.- Parameters:
buffer
- the ByteBuffer to fill from this streamoffset
- the offset inb
from which to start filling; expected to be non-negative and no greater thanbuffer.capacity() - len
len
- 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
void seek(long pos) throws IOException
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
- ifpos
is invalid or the seek fails- See Also:
getFilePointer()
-
skipBytes
long skipBytes(long n) throws IOException
Along
variant ofDataInput.skipBytes(int)
.- Parameters:
n
- the number of bytes to skip- Returns:
- the number of bytes skipped
- Throws:
IOException
- if the operation failed
-
write
void write(ByteBuffer buf) throws IOException
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
void write(ByteBuffer buf, int off, int len) throws IOException
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 inb
from which to start writing; expected to be non-negative and no greater thanbuf.capacity() - len
len
- the number of bytes to write; expected to be positive and no greater thanbuf.capacity() - offset
- Throws:
IOException
- if writing is not possible
-
-