Package org.scijava.io.handle
Interface StreamHandle<L extends Location>
-
- All Superinterfaces:
AutoCloseable,Closeable,Comparable<Prioritized>,Contextual,DataHandle<L>,DataInput,DataOutput,HasPluginInfo,Identifiable,Locatable,Logged,Prioritized,RichPlugin,SciJavaPlugin,Typed<L>,TypedPlugin<L>,Versioned,WrapperPlugin<L>
- All Known Subinterfaces:
ResettableStreamHandle<L>,SeekableStreamHandle<L>
- All Known Implementing Classes:
AbstractSeekableStreamHandle,AbstractStreamHandle
public interface StreamHandle<L extends Location> extends DataHandle<L>
- Author:
- Curtis Rueden, Melissa Linkert, Gabriel Einsdorf
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.scijava.io.handle.DataHandle
DataHandle.ByteOrder
-
-
Field Summary
-
Fields inherited from interface org.scijava.io.handle.DataHandle
DEFAULT_BLOCK_SIZE, MAX_SEARCH_SIZE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidadvance(long bytes)Increments the handle's offset by the given amount.default voidclose()default voidensureReadable(long count)Ensures that the handle has sufficient bytes available to read.default booleanensureWritable(long count)Ensures that the handle has the correct length to be written to, and extends it as required.InputStreamin()Gets an input stream for reading data, positioned at the current offset.default voidjump(long n)OutputStreamout()Gets an output stream for writing data, positioned at the current offset.default intread()Reads the next byte of data from the stream.default intread(byte[] b, int off, int len)Reads up tolenbytes of data from the stream into an array of bytes.default bytereadByte()voidresetStream()Resets the stream to its start.default voidseek(long pos)Sets the stream offset, measured from the beginning of the stream, at which the next read or write occurs.voidsetOffset(long offset)Sets the offset of the handle to the given position.default voidwrite(byte[] b, int off, int len)default voidwrite(int v)default voidwriteByte(int v)-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.io.handle.DataHandle
available, checksum, conversionBuffer, exists, findString, findString, findString, findString, getEncoding, getOrder, isBigEndian, isLittleEndian, isReadable, isWritable, lastModified, length, offset, read, readBoolean, readChar, readCString, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readString, readString, readUnsignedByte, readUnsignedShort, readUTF, setEncoding, setLength, setLittleEndian, setOrder, skip, skipBytes, write, writeBoolean, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLine, writeLong, writeShort, writeUTF
-
Methods inherited from interface org.scijava.plugin.HasPluginInfo
getInfo, setInfo
-
Methods inherited from interface org.scijava.Locatable
getLocation
-
Methods inherited from interface org.scijava.Prioritized
compareTo, getPriority, setPriority
-
Methods inherited from interface org.scijava.plugin.RichPlugin
getIdentifier, log
-
Methods inherited from interface org.scijava.Versioned
getVersion
-
Methods inherited from interface org.scijava.plugin.WrapperPlugin
get, set
-
-
-
-
Method Detail
-
in
InputStream in() throws IOException
Gets an input stream for reading data, positioned at the current offset.- Returns:
- the appropriate input stream, or null if the handle is write-only.
- Throws:
IOException
-
out
OutputStream out() throws IOException
Gets an output stream for writing data, positioned at the current offset.- Returns:
- the appropriate output stream, or null if the handle is read-only.
- Throws:
IOException
-
setOffset
void setOffset(long offset)
Sets the offset of the handle to the given position.This method is intended to be called only in conjunction with reading from the input stream, or writing to the output stream. Otherwise, the contents may get out of sync.
-
advance
default void advance(long bytes) throws IOExceptionIncrements the handle's offset by the given amount.This method is intended to be called only in conjunction with reading from the input stream, or writing to the output stream. Otherwise, the contents may get out of sync.
- Throws:
IOException
-
seek
default void seek(long pos) throws IOExceptionDescription copied from interface:DataHandleSets the stream offset, measured from the beginning of the stream, at which the next read or write occurs.- Specified by:
seekin interfaceDataHandle<L extends Location>- Throws:
IOException
-
resetStream
void resetStream() throws IOExceptionResets the stream to its start.- Throws:
IOException- If something goes wrong with the reset
-
jump
default void jump(long n) throws IOException, EOFException- Throws:
IOExceptionEOFException
-
ensureReadable
default void ensureReadable(long count) throws IOExceptionDescription copied from interface:DataHandleEnsures that the handle has sufficient bytes available to read.- Specified by:
ensureReadablein interfaceDataHandle<L extends Location>- Parameters:
count- Number of bytes to read.- Throws:
EOFException- If there are insufficient bytes available.IOException- If the handle is write-only, or something goes wrong with the check.- See Also:
DataHandle.available(long)
-
ensureWritable
default boolean ensureWritable(long count) throws IOExceptionDescription copied from interface:DataHandleEnsures that the handle has the correct length to be written to, and extends it as required.- Specified by:
ensureWritablein interfaceDataHandle<L extends Location>- Parameters:
count- Number of bytes to write.- Returns:
trueif the handle's length was sufficient, orfalseif the handle's length required an extension.- Throws:
IOException- If the handle is read-only, or something goes wrong with the check, or there is an error changing the handle's length.
-
read
default int read() throws IOExceptionDescription copied from interface:DataHandleReads the next byte of data from the stream.- Specified by:
readin interfaceDataHandle<L extends Location>- Returns:
- the next byte of data, or -1 if the end of the stream is reached.
- Throws:
IOException- - if an I/O error occurs.
-
readByte
default byte readByte() throws IOException- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
read
default int read(byte[] b, int off, int len) throws IOExceptionDescription copied from interface:DataHandleReads up tolenbytes of data from the stream into an array of bytes.- Specified by:
readin interfaceDataHandle<L extends Location>- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException
-
write
default void write(int v) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
writeByte
default void writeByte(int v) throws IOException- Specified by:
writeBytein interfaceDataHandle<L extends Location>- Specified by:
writeBytein interfaceDataOutput- Throws:
IOException
-
write
default void write(byte[] b, int off, int len) throws IOException- Specified by:
writein interfaceDataOutput- Throws:
IOException
-
close
default void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-