Package loci.common
Interface IRandomAccess
- All Superinterfaces:
java.io.DataInput
,java.io.DataOutput
- All Known Implementing Classes:
AbstractNIOHandle
,ByteArrayHandle
,BZip2Handle
,FileHandle
,GZipHandle
,NIOFileHandle
,S3Handle
,StreamHandle
,URLHandle
,ZipHandle
public interface IRandomAccess
extends java.io.DataInput, java.io.DataOutput
Interface for random access into structures (e.g., files or arrays).
- Author:
- Curtis Rueden ctrueden at wisc.edu
-
Method Summary
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.java.nio.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(java.nio.ByteBuffer buffer)
Reads up to buffer.capacity() bytes of data from this stream into a ByteBuffer.int
read(java.nio.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(java.nio.ByteOrder order)
Sets the byte order (endianness) of the stream.long
skipBytes(long n)
Along
variant ofDataInput.skipBytes(int)
.void
write(java.nio.ByteBuffer buf)
Writes up to buffer.capacity() bytes of data from the given ByteBuffer to this stream.void
write(java.nio.ByteBuffer buf, int off, int len)
Writes up to len bytes of data from the given ByteBuffer to this stream.
-
Method Details
-
close
void close() throws java.io.IOExceptionCloses this random access stream and releases any system resources associated with the stream.- Throws:
java.io.IOException
- if the underlying stream(s) could not be closed
-
getFilePointer
long getFilePointer() throws java.io.IOExceptionReturns 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:
java.io.IOException
- if the offset cannot be retrieved
-
exists
boolean exists() throws java.io.IOExceptionReturns whether this refers to a valid object- Returns:
- true if this refers to a valid object
- Throws:
java.io.IOException
- if unable to determine whether the object is valid
-
length
long length() throws java.io.IOExceptionReturns the length of this stream.- Returns:
- the length in bytes of the stream
- Throws:
java.io.IOException
- if the length cannot be retrieved
-
getOrder
java.nio.ByteOrder getOrder()Returns the current order (endianness) of the stream.- Returns:
- See above.
-
setOrder
void setOrder(java.nio.ByteOrder order)Sets the byte order (endianness) of the stream.- Parameters:
order
- Order to set.
-
read
int read(byte[] b) throws java.io.IOExceptionReads 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:
java.io.IOException
- if reading is not possible
-
read
int read(byte[] b, int off, int len) throws java.io.IOExceptionReads 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:
java.io.IOException
- if reading is not possible
-
read
int read(java.nio.ByteBuffer buffer) throws java.io.IOExceptionReads 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:
java.io.IOException
- if reading is not possible
-
read
int read(java.nio.ByteBuffer buffer, int offset, int len) throws java.io.IOExceptionReads 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:
java.io.IOException
- if reading is not possible
-
seek
void seek(long pos) throws java.io.IOExceptionSets 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:
java.io.IOException
- ifpos
is invalid or the seek fails- See Also:
getFilePointer()
-
skipBytes
long skipBytes(long n) throws java.io.IOExceptionAlong
variant ofDataInput.skipBytes(int)
.- Parameters:
n
- the number of bytes to skip- Returns:
- the number of bytes skipped
- Throws:
java.io.IOException
- if the operation failed
-
write
void write(java.nio.ByteBuffer buf) throws java.io.IOExceptionWrites 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:
java.io.IOException
- if writing is not possible
-
write
void write(java.nio.ByteBuffer buf, int off, int len) throws java.io.IOExceptionWrites 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:
java.io.IOException
- if writing is not possible
-