public interface DataHandle<L extends Location> extends WrapperPlugin<L>, DataInput, DataOutput, Closeable
Location
(e.g., files or arrays).DataHandleInputStream
,
DataHandleOutputStream
Modifier and Type | Interface and Description |
---|---|
static class |
DataHandle.ByteOrder |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BLOCK_SIZE
Default block size to use when searching through the stream.
|
static int |
MAX_SEARCH_SIZE
Default bound on bytes to search when searching through the stream.
|
Modifier and Type | Method and Description |
---|---|
default long |
available(long count)
Gets the number of bytes which can be read from, or written to, the
data handle, bounded by the specified number of bytes.
|
default String |
checksum()
Gets a "fast" checksum which succinctly represents the contents of the data
stream.
|
byte[] |
conversionBuffer() |
default void |
ensureReadable(long count)
Ensures that the handle has sufficient bytes available to read.
|
default boolean |
ensureWritable(long count)
Ensures that the handle has the correct length to be written to, and
extends it as required.
|
boolean |
exists()
Tests whether this handle's location actually exists at the source.
|
default String |
findString(boolean saveString,
int blockSize,
String... terminators)
Reads or skips a string ending with one of the given terminating
substrings, using the specified block size for buffering.
|
default String |
findString(boolean saveString,
String... terminators)
Reads or skips a string ending with one of the given terminating
substrings.
|
default String |
findString(int blockSize,
String... terminators)
Reads a string ending with one of the given terminating substrings, using
the specified block size for buffering.
|
default String |
findString(String... terminators)
Reads a string ending with one of the given terminating substrings.
|
String |
getEncoding()
Gets the native encoding of the stream.
|
DataHandle.ByteOrder |
getOrder()
Returns the byte order of the stream.
|
default boolean |
isBigEndian()
Returns true iff the stream's order is
DataHandle.ByteOrder.BIG_ENDIAN . |
default boolean |
isLittleEndian()
Returns true iff the stream's order is
DataHandle.ByteOrder.LITTLE_ENDIAN . |
boolean |
isReadable()
Gets whether reading from this handle is supported.
|
boolean |
isWritable()
Gets whether writing to this handle is supported.
|
default Date |
lastModified()
Gets the last modified timestamp of the location.
|
long |
length()
Returns the length of the data in bytes.
|
long |
offset()
Returns the current offset in the stream.
|
default int |
read()
Reads the next byte of data from the stream.
|
default int |
read(byte[] b)
Reads up to b.length bytes of data from the stream into an array of bytes.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from the stream into an array of
bytes. |
default boolean |
readBoolean() |
default char |
readChar() |
default String |
readCString()
Reads a string of arbitrary length, terminated by a null char.
|
default double |
readDouble() |
default float |
readFloat() |
default void |
readFully(byte[] b) |
default void |
readFully(byte[] b,
int off,
int len) |
default int |
readInt() |
default String |
readLine() |
default long |
readLong() |
default short |
readShort() |
default String |
readString(int n)
Reads a string of up to length n.
|
default String |
readString(String lastChars)
Reads a string ending with one of the characters in the given string.
|
default int |
readUnsignedByte() |
default int |
readUnsignedShort() |
default String |
readUTF() |
void |
seek(long pos)
Sets the stream offset, measured from the beginning of the stream, at which
the next read or write occurs.
|
void |
setEncoding(String encoding)
Sets the native encoding of the stream.
|
void |
setLength(long length)
Sets the new length of the handle.
|
default void |
setLittleEndian(boolean little)
Sets the endianness of the stream.
|
void |
setOrder(DataHandle.ByteOrder order)
Sets the byte order of the stream.
|
default long |
skip(long n)
Skips over and discards
n bytes of data from the stream. |
default int |
skipBytes(int n) |
default void |
write(byte[] b) |
default void |
writeBoolean(boolean v) |
default void |
writeByte(int v) |
default void |
writeBytes(String s) |
default void |
writeChar(int v) |
default void |
writeChars(String s) |
default void |
writeDouble(double v) |
default void |
writeFloat(float v) |
default void |
writeInt(int v) |
default void |
writeLine(String string)
Writes the provided string, followed by a newline character.
|
default void |
writeLong(long v) |
default void |
writeShort(int v) |
default void |
writeUTF(String str) |
get, set
getIdentifier, log
context, getContext, setContext
compareTo, getPriority, setPriority
getInfo, setInfo
getLocation
getVersion
write, write
static final int DEFAULT_BLOCK_SIZE
static final int MAX_SEARCH_SIZE
boolean isReadable()
boolean isWritable()
boolean exists() throws IOException
IOException
- If something goes wrong with the existence check.default Date lastModified() throws IOException
IOException
- If something goes wrong with the last modified check.default String checksum() throws IOException
No guarantee is made about the exact nature of the checksum (e.g., SHA-1 or MD5), only that the value is deterministic for this particular location with its current contents. In other words: if a checksum differs from a previous inquiry, you can be sure the contents have changed; conversely, if the checksum is still the same, the contents are highly likely to be unchanged.
IOException
- If something goes wrong when accessing the checksum.long offset() throws IOException
IOException
void seek(long pos) throws IOException
IOException
long length() throws IOException
IOException
void setLength(long length) throws IOException
length
- New length.IOException
- If there is an error changing the handle's length.default long available(long count) throws IOException
In the case of reading, attempting to read the returned number of bytes is
guaranteed not to throw EOFException
. However, be aware that the
following methods might still process fewer bytes than indicated
by this method:
In the case of writing, attempting to write the returned number of bytes is guaranteed not to expand the length of the handle; i.e., the write will only overwrite bytes already within the handle's bounds.
count
- Desired number of bytes to read/write.IOException
- If something goes wrong with the check.default void ensureReadable(long count) throws IOException
count
- Number of bytes to read.EOFException
- If there are insufficient bytes available.IOException
- If the handle is write-only, or something goes wrong
with the check.available(long)
default boolean ensureWritable(long count) throws IOException
count
- Number of bytes to write.true
if the handle's length was sufficient, or
false
if the handle's length required an extension.IOException
- If the handle is read-only, or something goes wrong
with the check, or there is an error changing the handle's
length.DataHandle.ByteOrder getOrder()
void setOrder(DataHandle.ByteOrder order)
order
- Order to set.default boolean isBigEndian()
DataHandle.ByteOrder.BIG_ENDIAN
.getOrder()
default boolean isLittleEndian()
DataHandle.ByteOrder.LITTLE_ENDIAN
.getOrder()
default void setLittleEndian(boolean little)
little
- If true, sets the order to DataHandle.ByteOrder.LITTLE_ENDIAN
;
otherwise, sets the order to DataHandle.ByteOrder.BIG_ENDIAN
.setOrder(ByteOrder)
String getEncoding()
void setEncoding(String encoding)
byte[] conversionBuffer()
default String readCString() throws IOException
IOException
default String readString(int n) throws IOException
IOException
default String readString(String lastChars) throws IOException
IOException
findString(String...)
default String findString(String... terminators) throws IOException
terminators
- The strings for which to search.IOException
default String findString(boolean saveString, String... terminators) throws IOException
saveString
- Whether to collect the string from the current offset to
the terminating bytes, and return it. If false, returns null.terminators
- The strings for which to search.IOException
- If saveString flag is set and the maximum search length
(512 MB) is exceeded.default String findString(int blockSize, String... terminators) throws IOException
blockSize
- The block size to use when reading bytes in chunks.terminators
- The strings for which to search.IOException
default String findString(boolean saveString, int blockSize, String... terminators) throws IOException
saveString
- Whether to collect the string from the current offset to
the terminating bytes, and return it. If false, returns null.blockSize
- The block size to use when reading bytes in chunks.terminators
- The strings for which to search.IOException
- If saveString flag is set and the maximum search length
(512 MB) is exceeded.default void writeLine(String string) throws IOException
string
- The string to write.IOException
- If an I/O error occurs.default int read() throws IOException
IOException
- - if an I/O error occurs.default int read(byte[] b) throws IOException
IOException
int read(byte[] b, int off, int len) throws IOException
len
bytes of data from the stream into an array of
bytes.IOException
default long skip(long n) throws IOException
n
bytes of data from the stream. The
skip
method may, for a variety of reasons, end up skipping over
some smaller number of bytes, possibly 0
. This may result from any
of a number of conditions; reaching end of file before n
bytes have
been skipped is only one possibility. The actual number of bytes skipped is
returned. If n
is negative, no bytes are skipped.n
- - the number of bytes to be skipped.IOException
- - if an I/O error occurs.default void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
default void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
default int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
default boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
default int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
default short readShort() throws IOException
readShort
in interface DataInput
IOException
default int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
default char readChar() throws IOException
readChar
in interface DataInput
IOException
default int readInt() throws IOException
readInt
in interface DataInput
IOException
default long readLong() throws IOException
readLong
in interface DataInput
IOException
default float readFloat() throws IOException
readFloat
in interface DataInput
IOException
default double readDouble() throws IOException
readDouble
in interface DataInput
IOException
default String readLine() throws IOException
readLine
in interface DataInput
IOException
default String readUTF() throws IOException
readUTF
in interface DataInput
IOException
default void write(byte[] b) throws IOException
write
in interface DataOutput
IOException
default void writeBoolean(boolean v) throws IOException
writeBoolean
in interface DataOutput
IOException
default void writeByte(int v) throws IOException
writeByte
in interface DataOutput
IOException
default void writeShort(int v) throws IOException
writeShort
in interface DataOutput
IOException
default void writeChar(int v) throws IOException
writeChar
in interface DataOutput
IOException
default void writeInt(int v) throws IOException
writeInt
in interface DataOutput
IOException
default void writeLong(long v) throws IOException
writeLong
in interface DataOutput
IOException
default void writeFloat(float v) throws IOException
writeFloat
in interface DataOutput
IOException
default void writeDouble(double v) throws IOException
writeDouble
in interface DataOutput
IOException
default void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
IOException
default void writeChars(String s) throws IOException
writeChars
in interface DataOutput
IOException
default void writeUTF(String str) throws IOException
writeUTF
in interface DataOutput
IOException
Copyright © 2015–2022 SciJava. All rights reserved.