Package org.scijava.io.handle
Class ReadBufferDataHandle<L extends Location>
- 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<L>
-
- org.scijava.io.handle.ReadBufferDataHandle<L>
-
- All Implemented Interfaces:
Closeable,DataInput,DataOutput,AutoCloseable,Comparable<Prioritized>,Contextual,Identifiable,DataHandle<L>,Locatable,Logged,HasPluginInfo,RichPlugin,SciJavaPlugin,TypedPlugin<L>,WrapperPlugin<L>,Prioritized,Typed<L>,Versioned
public class ReadBufferDataHandle<L extends Location> extends AbstractHigherOrderHandle<L>
Read-only bufferedDataHandle. It buffers the underlying handle into a fixed number of pages, swapping them out when necessary.
-
-
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 ReadBufferDataHandle(DataHandle<L> handle)Creates aReadBufferDataHandlewrapping the provided handle using the default values for the size of the pages (10000 byte) and number of pages (DEFAULT_NUM_PAGES).ReadBufferDataHandle(DataHandle<L> handle, int pageSize)Creates aReadBufferDataHandlewrapping the provided handle using the default value for the number of pages (DEFAULT_NUM_PAGES).ReadBufferDataHandle(DataHandle<L> handle, int pageSize, int numPages)Creates aReadBufferDataHandlewrapping the provided handle.
-
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.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 targetOffset, 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.voidwrite(byte[] b, int off, int len)voidwrite(int b)-
Methods inherited from class org.scijava.io.handle.AbstractHigherOrderHandle
close, ensureOpen, 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, skip, 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
-
ReadBufferDataHandle
public ReadBufferDataHandle(DataHandle<L> handle)
Creates aReadBufferDataHandlewrapping the provided handle using the default values for the size of the pages (10000 byte) and number of pages (DEFAULT_NUM_PAGES).- Parameters:
handle- the handle to wrap
-
ReadBufferDataHandle
public ReadBufferDataHandle(DataHandle<L> handle, int pageSize)
Creates aReadBufferDataHandlewrapping the provided handle using the default value for the number of pages (DEFAULT_NUM_PAGES).- Parameters:
handle- the handle to wrappageSize- the size of the used pages
-
ReadBufferDataHandle
public ReadBufferDataHandle(DataHandle<L> handle, int pageSize, int numPages)
Creates aReadBufferDataHandlewrapping the provided handle.- Parameters:
handle- the handle to wrappageSize- the size of the used pagesnumPages- the number of pages to use
-
-
Method Detail
-
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
-
length
public long length() throws IOExceptionDescription copied from interface:DataHandleReturns the length of the data in bytes.- Specified by:
lengthin interfaceDataHandle<L extends Location>- Overrides:
lengthin classAbstractHigherOrderHandle<L extends Location>- Returns:
- The length, or -1 if the length is unknown.
- Throws:
IOException
-
read
public int read(byte[] b, int targetOffset, 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
-
readByte
public byte readByte() throws IOException- Throws:
IOException
-
isReadable
public boolean isReadable()
Description copied from interface:DataHandleGets whether reading from this handle is supported.- Specified by:
isReadablein interfaceDataHandle<L extends Location>- Overrides:
isReadablein classAbstractHigherOrderHandle<L extends Location>
-
offset
public long offset() throws IOExceptionDescription copied from interface:DataHandleReturns the current offset in the stream.- Throws:
IOException
-
cleanup
protected void cleanup()
Description copied from class:AbstractHigherOrderHandleClean up data structures after a handle has been closed in theAbstractHigherOrderHandle.close()method.- Specified by:
cleanupin classAbstractHigherOrderHandle<L extends Location>
-
write
public void write(int b) throws IOException- Throws:
IOException
-
write
public void write(byte[] b, int off, int len) throws IOException- 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.
-
-