public class WriteBufferDataHandle extends AbstractHigherOrderHandle<Location>
DataHandle
and acts as a write buffer.DataHandle.ByteOrder
DEFAULT_BLOCK_SIZE, MAX_SEARCH_SIZE
Constructor and Description |
---|
WriteBufferDataHandle(DataHandle<Location> handle)
Creates a
WriteBufferDataHandle that wraps the given
DataHandle , the default size for the buffer is used
( bytes). |
WriteBufferDataHandle(DataHandle<Location> handle,
int bufferSize)
Creates a
WriteBufferDataHandle that wraps the given
DataHandle |
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup()
Clean up data structures after a handle has been closed in the
AbstractHigherOrderHandle.close() method. |
protected void |
ensureOpen() |
boolean |
isReadable()
Gets whether reading from this handle is supported.
|
long |
length()
Returns the length of the data in bytes.
|
long |
offset()
Returns the current offset in the stream.
|
int |
read(byte[] b,
int off,
int len)
Reads up to
len bytes of data from the stream into an array of
bytes. |
byte |
readByte() |
void |
seek(long pos)
Sets the stream offset, measured from the beginning of the stream, at which
the next read or write occurs.
|
void |
setLength(long length)
Sets the new length of the handle.
|
long |
skip(long n)
Skips over and discards
n bytes of data from the stream. |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
close, exists, getType, handle, isWritable
conversionBuffer, getEncoding, getOrder, setEncoding, setOrder
get, set
supports
getInfo, getPriority, setInfo, setPriority, toString
context, getContext
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
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
get, set
getIdentifier, log
context, getContext, setContext
compareTo, getPriority, setPriority
getInfo, setInfo
getLocation
getVersion
public WriteBufferDataHandle(DataHandle<Location> handle)
WriteBufferDataHandle
that wraps the given
DataHandle
, the default size for the buffer is used
( bytes).handle
- the handle to wrappublic WriteBufferDataHandle(DataHandle<Location> handle, int bufferSize)
WriteBufferDataHandle
that wraps the given
DataHandle
handle
- the handle to wrapbufferSize
- the size of the write buffer in bytespublic void write(int b) throws IOException
IOException
public void write(byte[] b, int off, int len) throws IOException
IOException
public long length() throws IOException
DataHandle
length
in interface DataHandle<Location>
length
in class AbstractHigherOrderHandle<Location>
IOException
public void setLength(long length) throws IOException
DataHandle
length
- New length.IOException
- If there is an error changing the handle's length.public boolean isReadable()
DataHandle
isReadable
in interface DataHandle<Location>
isReadable
in class AbstractHigherOrderHandle<Location>
protected void ensureOpen() throws IOException
ensureOpen
in class AbstractHigherOrderHandle<Location>
IOException
- if this handle has been closedpublic long offset() throws IOException
DataHandle
IOException
public void seek(long pos) throws IOException
DataHandle
IOException
public long skip(long n) throws IOException
DataHandle
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.public byte readByte() throws IOException
IOException
public int read(byte[] b, int off, int len) throws IOException
DataHandle
len
bytes of data from the stream into an array of
bytes.IOException
protected void cleanup() throws IOException
AbstractHigherOrderHandle
AbstractHigherOrderHandle.close()
method.cleanup
in class AbstractHigherOrderHandle<Location>
IOException
Copyright © 2015–2022 SciJava. All rights reserved.