Package org.scijava.io.handle
Class WriteBufferDataHandle
- java.lang.Object
-
- org.scijava.AbstractContextual
-
- org.scijava.plugin.AbstractRichPlugin
-
- org.scijava.plugin.AbstractTypedPlugin<D>
-
- org.scijava.plugin.AbstractWrapperPlugin<L>
-
- org.scijava.io.handle.AbstractDataHandle<L>
-
- org.scijava.io.handle.AbstractHigherOrderHandle<Location>
-
- org.scijava.io.handle.WriteBufferDataHandle
-
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable,Comparable<Prioritized>,Contextual,Identifiable,DataHandle<Location>,Locatable,Logged,HasPluginInfo,RichPlugin,SciJavaPlugin,TypedPlugin<Location>,WrapperPlugin<Location>,Prioritized,Typed<Location>,Versioned
public class WriteBufferDataHandle extends AbstractHigherOrderHandle<Location>
Wraps aDataHandleand acts as a write buffer.- Author:
- 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
-
-
Constructor Summary
Constructors Constructor Description WriteBufferDataHandle(DataHandle<Location> handle)Creates aWriteBufferDataHandlethat wraps the givenDataHandle, the default size for the buffer is used (10000 bytes).WriteBufferDataHandle(DataHandle<Location> handle, int bufferSize)Creates aWriteBufferDataHandlethat wraps the givenDataHandle
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcleanup()Clean up data structures after a handle has been closed in theAbstractHigherOrderHandle.close()method.protected voidensureOpen()booleanisReadable()Gets whether reading from this handle is supported.longlength()Returns the length of the data in bytes.longoffset()Returns the current offset in the stream.intread(byte[] b, int off, int len)Reads up tolenbytes of data from the stream into an array of bytes.bytereadByte()voidseek(long pos)Sets the stream offset, measured from the beginning of the stream, at which the next read or write occurs.voidsetLength(long length)Sets the new length of the handle.longskip(long n)Skips over and discardsnbytes of data from the stream.voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class org.scijava.io.handle.AbstractHigherOrderHandle
close, exists, getType, handle, isWritable
-
Methods inherited from class org.scijava.io.handle.AbstractDataHandle
conversionBuffer, getEncoding, getOrder, setEncoding, setOrder
-
Methods inherited from class org.scijava.plugin.AbstractWrapperPlugin
get, set
-
Methods inherited from class org.scijava.plugin.AbstractTypedPlugin
supports
-
Methods inherited from class org.scijava.plugin.AbstractRichPlugin
getInfo, getPriority, setInfo, setPriority, toString
-
Methods inherited from class org.scijava.AbstractContextual
context, getContext
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.scijava.Contextual
context, getContext, setContext
-
Methods inherited from interface org.scijava.io.handle.DataHandle
available, checksum, ensureReadable, ensureWritable, findString, findString, findString, findString, isBigEndian, isLittleEndian, lastModified, read, read, readBoolean, readChar, readCString, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readString, readString, readUnsignedByte, readUnsignedShort, readUTF, setLittleEndian, skipBytes, write, writeBoolean, writeByte, 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
-
-
-
-
Constructor Detail
-
WriteBufferDataHandle
public WriteBufferDataHandle(DataHandle<Location> handle)
Creates aWriteBufferDataHandlethat wraps the givenDataHandle, the default size for the buffer is used (10000 bytes).- Parameters:
handle- the handle to wrap
-
WriteBufferDataHandle
public WriteBufferDataHandle(DataHandle<Location> handle, int bufferSize)
Creates aWriteBufferDataHandlethat wraps the givenDataHandle- Parameters:
handle- the handle to wrapbufferSize- the size of the write buffer in bytes
-
-
Method Detail
-
write
public void write(int b) throws IOException- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- Throws:
IOException
-
length
public long length() throws IOExceptionDescription copied from interface:DataHandleReturns the length of the data in bytes.- Specified by:
lengthin interfaceDataHandle<Location>- Overrides:
lengthin classAbstractHigherOrderHandle<Location>- Returns:
- The length, or -1 if the length is unknown.
- Throws:
IOException
-
setLength
public void setLength(long length) throws IOExceptionDescription copied from interface:DataHandleSets the new length of the handle.- Parameters:
length- New length.- Throws:
IOException- If there is an error changing the handle's length.
-
isReadable
public boolean isReadable()
Description copied from interface:DataHandleGets whether reading from this handle is supported.- Specified by:
isReadablein interfaceDataHandle<Location>- Overrides:
isReadablein classAbstractHigherOrderHandle<Location>
-
ensureOpen
protected void ensureOpen() throws IOException- Overrides:
ensureOpenin classAbstractHigherOrderHandle<Location>- Throws:
IOException- if this handle has been closed
-
offset
public long offset() throws IOExceptionDescription copied from interface:DataHandleReturns the current offset in the stream.- Throws:
IOException
-
seek
public 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.- Throws:
IOException
-
skip
public long skip(long n) throws IOExceptionDescription copied from interface:DataHandleSkips over and discardsnbytes of data from the stream. Theskipmethod may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly0. This may result from any of a number of conditions; reaching end of file beforenbytes have been skipped is only one possibility. The actual number of bytes skipped is returned. Ifnis negative, no bytes are skipped.- Parameters:
n- - the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- - if an I/O error occurs.
-
readByte
public byte readByte() throws IOException- Throws:
IOException
-
read
public 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.- Returns:
- the total number of bytes read into the buffer.
- Throws:
IOException
-
cleanup
protected void cleanup() throws IOExceptionDescription copied from class:AbstractHigherOrderHandleClean up data structures after a handle has been closed in theAbstractHigherOrderHandle.close()method.- Specified by:
cleanupin classAbstractHigherOrderHandle<Location>- Throws:
IOException
-
-