public class BufferedIO extends ConcurrentCloseable implements IO.Readable.Seekable, IO.Readable.Buffered, IO.KnownSize
Modifier and Type | Class and Description |
---|---|
static class |
BufferedIO.MemoryManagement
Manages memory usage and delayed write operations of BufferedIO instances.
|
static class |
BufferedIO.ReadWrite
Writable BufferedIO.
|
IO.Seekable.SeekType
IO.KnownSize, IO.OperationType, IO.OutputToInput, IO.PositionKnown, IO.Readable, IO.ReadableByteStream, IO.Resizable, IO.Writable, IO.WritableByteStream, IO.WriterAsync
CloseableListenable.Impl
IO.Readable.Buffered, IO.Readable.Seekable
Modifier and Type | Field and Description |
---|---|
protected int |
bufferSize |
protected net.lecousin.framework.io.buffering.BufferedIO.BufferTable |
bufferTable |
protected boolean |
closing |
protected int |
firstBufferSize |
protected IO.Readable.Seekable |
io |
protected BufferedIO.MemoryManagement |
memory |
protected long |
position |
protected boolean |
preLoadNextBuffer |
protected long |
size |
Constructor and Description |
---|
BufferedIO(IO.Readable.Seekable io,
int firstBufferSize,
int nextBuffersSize,
boolean preLoadNextBuffer)
Constructor.
|
BufferedIO(IO.Readable.Seekable io,
long size,
int firstBufferSize,
int nextBuffersSize,
boolean preLoadNextBuffer)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
ISynchronizationPoint<IOException> |
canStartReading()
Return a synchronization point that is unblocked when data is ready to be read.
|
protected void |
closeResources(SynchronizationPoint<Exception> ondone) |
protected ISynchronizationPoint<Exception> |
closeUnderlyingResources() |
protected long |
getBufferIndex(long pos) |
protected int |
getBufferOffset(long pos) |
protected long |
getBufferPosition(long index) |
long |
getPosition()
Return the current position.
|
byte |
getPriority()
Return the priority.
|
AsyncWork<Long,IOException> |
getSizeAsync()
Asynchronous operation to get the size of the IO.
|
long |
getSizeSync()
Synchronous operation to get the size of the IO.
|
String |
getSourceDescription()
Describe the IO, which can be used for logging or debugging purposes.
|
TaskManager |
getTaskManager()
Return the TaskManager used for asynchronous operations.
|
IO |
getWrappedIO()
If this IO is wrapping another one (such as adding Buffered capabilities), this method returns it,
or null if it does not wrap another IO.
|
protected void |
preLoadBuffer(long pos) |
int |
read()
Read next byte.
|
int |
read(byte[] buffer,
int offset,
int len)
Read bytes into the given buffer, starting to store them at the given offset, and with the given maximum number of bytes.
|
int |
readAsync()
Read a single byte if possible.
|
AsyncWork<Integer,IOException> |
readAsync(ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Asynchronous read operation.
|
AsyncWork<Integer,IOException> |
readAsync(long pos,
ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Same as
IO.Readable.readAsync(ByteBuffer, RunnableWithParameter) but read at the given position. |
int |
readFully(byte[] buffer)
Read bytes to fill the given buffer, and return the number of bytes read which is less than the
size of the buffer only if the end of the IO is reached, and so may return 0.
|
AsyncWork<Integer,IOException> |
readFullyAsync(ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Asynchronous read operation to fully fill the given buffer.
|
AsyncWork<Integer,IOException> |
readFullyAsync(long pos,
ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
Same as
IO.Readable.readFullyAsync(ByteBuffer, RunnableWithParameter) but read at the given position. |
int |
readFullySync(ByteBuffer buffer)
Synchronous read operation to fully fill the given buffer.
|
int |
readFullySync(long pos,
ByteBuffer buffer)
Same as
IO.Readable.readFullySync(ByteBuffer) but read at the given position. |
AsyncWork<Integer,IOException> |
readFullySyncIfPossible(ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
While readAsync methods are supposed to do the job in a separate thread, this method
fills the given buffer synchronously if enough data is already buffered, else it finishes asynchronously.
|
AsyncWork<Integer,IOException> |
readFullySyncIfPossible(long pos,
ByteBuffer buffer,
RunnableWithParameter<Pair<Integer,IOException>> ondone)
While readAsync methods are supposed to do the job in a separate thread, this method
fills the given buffer synchronously if enough data is already buffered, else it finishes asynchronously.
|
AsyncWork<ByteBuffer,IOException> |
readNextBufferAsync(RunnableWithParameter<Pair<ByteBuffer,IOException>> ondone)
Retrieve a buffer of bytes in the most efficient way depending on the implementation of Buffered.
This method is similar to readAsync, it read some bytes that are immediately available with a minimum of operations. |
int |
readSync(ByteBuffer buffer)
Read synchronously into the given buffer.
|
int |
readSync(long pos,
ByteBuffer buffer)
Same as
IO.Readable.readSync(ByteBuffer) but read at the given position. |
AsyncWork<Long,IOException> |
seekAsync(IO.Seekable.SeekType type,
long move,
RunnableWithParameter<Pair<Long,IOException>> ondone)
Returns the new position.
|
long |
seekSync(IO.Seekable.SeekType type,
long move)
Returns the new position.
|
void |
setPriority(byte priority)
Set the priority of asynchronous operations.
|
int |
skip(int skip)
Same as
IO.Readable.skipSync(long) but limited to an integer. |
AsyncWork<Long,IOException> |
skipAsync(long n,
RunnableWithParameter<Pair<Long,IOException>> ondone)
Returns the number of bytes skipped.
|
long |
skipSync(long n)
Returns the number of bytes skipped.
|
addCloseListener, addCloseListener, close, closeAsync, isClosed, isClosing, lockClose, operation, operation, removeCloseListener, removeCloseListener, unlockClose
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
readAsync, readFullyAsync
seekAsync
lockClose, unlockClose
close
closeAsync
addCloseListener, addCloseListener, close, isClosed, removeCloseListener, removeCloseListener
readFullySyncIfPossible, readNextBufferAsync
readAsync, readFullyAsync, skipAsync
readByte
protected BufferedIO.MemoryManagement memory
protected IO.Readable.Seekable io
protected long position
protected long size
protected boolean closing
protected net.lecousin.framework.io.buffering.BufferedIO.BufferTable bufferTable
protected boolean preLoadNextBuffer
protected int firstBufferSize
protected int bufferSize
public BufferedIO(IO.Readable.Seekable io, long size, int firstBufferSize, int nextBuffersSize, boolean preLoadNextBuffer)
public BufferedIO(IO.Readable.Seekable io, int firstBufferSize, int nextBuffersSize, boolean preLoadNextBuffer) throws IOException
IOException
protected long getBufferIndex(long pos)
protected int getBufferOffset(long pos)
protected long getBufferPosition(long index)
protected void preLoadBuffer(long pos)
protected ISynchronizationPoint<Exception> closeUnderlyingResources()
closeUnderlyingResources
in class ConcurrentCloseable
protected void closeResources(SynchronizationPoint<Exception> ondone)
closeResources
in class ConcurrentCloseable
public byte getPriority()
ConcurrentCloseable
getPriority
in interface IO
getPriority
in class ConcurrentCloseable
public void setPriority(byte priority)
IO
setPriority
in interface IO
public String getSourceDescription()
IO
getSourceDescription
in interface IO
public IO getWrappedIO()
IO
getWrappedIO
in interface IO
public TaskManager getTaskManager()
IO
getTaskManager
in interface IO
public long getSizeSync()
IO.KnownSize
getSizeSync
in interface IO.KnownSize
public AsyncWork<Long,IOException> getSizeAsync()
IO.KnownSize
getSizeAsync
in interface IO.KnownSize
public long getPosition()
IO.PositionKnown
getPosition
in interface IO.PositionKnown
public int read() throws IOException
IO.ReadableByteStream
read
in interface IO.ReadableByteStream
IOException
public int read(byte[] buffer, int offset, int len) throws IOException
IO.ReadableByteStream
read
in interface IO.ReadableByteStream
IOException
public int readSync(long pos, ByteBuffer buffer) throws IOException
IO.Readable.Seekable
IO.Readable.readSync(ByteBuffer)
but read at the given position.
The current position is changed to the given position plus the number of bytes read.readSync
in interface IO.Readable.Seekable
IOException
public int readSync(ByteBuffer buffer) throws IOException
IO.Readable
readSync
in interface IO.Readable
buffer
- buffer to fillIOException
public int readFullySync(long pos, ByteBuffer buffer) throws IOException
IO.Readable.Seekable
IO.Readable.readFullySync(ByteBuffer)
but read at the given position.
The current position is changed to the given position plus the number of bytes read.readFullySync
in interface IO.Readable.Seekable
IOException
public int readFullySync(ByteBuffer buffer) throws IOException
IO.Readable
readFullySync
in interface IO.Readable
buffer
- the buffer to fillIOException
public int readFully(byte[] buffer) throws IOException
IO.ReadableByteStream
readFully
in interface IO.ReadableByteStream
IOException
public ISynchronizationPoint<IOException> canStartReading()
IO.Readable
canStartReading
in interface IO.Readable
canStartReading
in interface IO.ReadableByteStream
public int readAsync() throws IOException
IO.Readable.Buffered
readAsync
in interface IO.Readable.Buffered
IOException
public AsyncWork<Integer,IOException> readAsync(long pos, ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
IO.Readable.Seekable
IO.Readable.readAsync(ByteBuffer, RunnableWithParameter)
but read at the given position.
The current position is changed to the given position plus the number of bytes read upon completion.readAsync
in interface IO.Readable.Seekable
public AsyncWork<Integer,IOException> readAsync(ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
IO.Readable
readAsync
in interface IO.Readable
buffer
- buffer to fillondone
- called before the returned AsyncWork is unblocked and its listeners are called.public AsyncWork<ByteBuffer,IOException> readNextBufferAsync(RunnableWithParameter<Pair<ByteBuffer,IOException>> ondone)
IO.Readable.Buffered
readNextBufferAsync
in interface IO.Readable.Buffered
public AsyncWork<Integer,IOException> readFullySyncIfPossible(ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
IO.Readable.Buffered
readFullySyncIfPossible
in interface IO.Readable.Buffered
public AsyncWork<Integer,IOException> readFullySyncIfPossible(long pos, ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
public AsyncWork<Integer,IOException> readFullyAsync(long pos, ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
IO.Readable.Seekable
IO.Readable.readFullyAsync(ByteBuffer, RunnableWithParameter)
but read at the given position.
The current position is changed to the given position plus the number of bytes read upon completion.readFullyAsync
in interface IO.Readable.Seekable
public AsyncWork<Integer,IOException> readFullyAsync(ByteBuffer buffer, RunnableWithParameter<Pair<Integer,IOException>> ondone)
IO.Readable
readFullyAsync
in interface IO.Readable
buffer
- the buffer to fillondone
- called before the returned AsyncWork is unblocked and its listeners are called.public long skipSync(long n)
IO.Readable
skipSync
in interface IO.Readable
public int skip(int skip)
IO.ReadableByteStream
IO.Readable.skipSync(long)
but limited to an integer.skip
in interface IO.ReadableByteStream
public AsyncWork<Long,IOException> skipAsync(long n, RunnableWithParameter<Pair<Long,IOException>> ondone)
IO.Readable
skipAsync
in interface IO.Readable
public long seekSync(IO.Seekable.SeekType type, long move)
IO.Seekable
seekSync
in interface IO.Seekable
public AsyncWork<Long,IOException> seekAsync(IO.Seekable.SeekType type, long move, RunnableWithParameter<Pair<Long,IOException>> ondone)
IO.Seekable
seekAsync
in interface IO.Seekable
Copyright © 2018. All rights reserved.