public class BufferedIO extends ConcurrentCloseable<IOException> 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.SeekTypeIO.KnownSize, IO.OperationType, IO.OutputToInput, IO.PositionKnown, IO.Readable, IO.ReadableByteStream, IO.Resizable, IO.Writable, IO.WritableByteStream, IO.WriterAsyncCloseableListenable.ImplIO.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 |
|---|---|
IAsync<IOException> |
canStartReading()
Return a synchronization point that is unblocked when data is ready to be read.
|
protected void |
closeResources(Async<IOException> ondone) |
protected IAsync<IOException> |
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.
|
AsyncSupplier<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.
|
AsyncSupplier<Integer,IOException> |
readAsync(ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Asynchronous read operation.
|
AsyncSupplier<Integer,IOException> |
readAsync(long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Same as
IO.Readable.readAsync(ByteBuffer, Consumer) 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.
|
AsyncSupplier<Integer,IOException> |
readFullyAsync(ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Asynchronous read operation to fully fill the given buffer.
|
AsyncSupplier<Integer,IOException> |
readFullyAsync(long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Same as
IO.Readable.readFullyAsync(ByteBuffer, Consumer) 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. |
AsyncSupplier<Integer,IOException> |
readFullySyncIfPossible(ByteBuffer buffer,
Consumer<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.
|
AsyncSupplier<Integer,IOException> |
readFullySyncIfPossible(long pos,
ByteBuffer buffer,
Consumer<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.
|
ByteBuffer |
readNextBuffer()
Retrieve a buffer of bytes in the most efficient way depending on the implementation of Buffered.
Its returns the immediately available bytes with a minimum of operations. |
AsyncSupplier<ByteBuffer,IOException> |
readNextBufferAsync(Consumer<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 reads 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. |
AsyncSupplier<Long,IOException> |
seekAsync(IO.Seekable.SeekType type,
long move,
Consumer<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. |
AsyncSupplier<Long,IOException> |
skipAsync(long n,
Consumer<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, unlockCloseclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitreadAsync, readFullyAsyncseekAsynccancelClosed, error, errorCancelledlockClose, unlockCloseclosecloseAfter, closeAsyncaddCloseListener, addCloseListener, close, isClosed, removeCloseListener, removeCloseListenerreadFullySyncIfPossible, readNextBufferAsyncreadAsync, readFullyAsync, skipAsyncreadByteprotected 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
IOExceptionprotected long getBufferIndex(long pos)
protected int getBufferOffset(long pos)
protected long getBufferPosition(long index)
protected void preLoadBuffer(long pos)
protected IAsync<IOException> closeUnderlyingResources()
closeUnderlyingResources in class ConcurrentCloseable<IOException>protected void closeResources(Async<IOException> ondone)
closeResources in class ConcurrentCloseable<IOException>public byte getPriority()
ConcurrentCloseablegetPriority in interface IOgetPriority in class ConcurrentCloseable<IOException>public void setPriority(byte priority)
IOsetPriority in interface IOpublic String getSourceDescription()
IOgetSourceDescription in interface IOpublic IO getWrappedIO()
IOgetWrappedIO in interface IOpublic TaskManager getTaskManager()
IOgetTaskManager in interface IOpublic long getSizeSync()
IO.KnownSizegetSizeSync in interface IO.KnownSizepublic AsyncSupplier<Long,IOException> getSizeAsync()
IO.KnownSizegetSizeAsync in interface IO.KnownSizepublic long getPosition()
IO.PositionKnowngetPosition in interface IO.PositionKnownpublic int read()
throws IOException
IO.ReadableByteStreamread in interface IO.ReadableByteStreamIOExceptionpublic int read(byte[] buffer,
int offset,
int len)
throws IOException
IO.ReadableByteStreamread in interface IO.ReadableByteStreamIOExceptionpublic int readSync(long pos,
ByteBuffer buffer)
throws IOException
IO.Readable.SeekableIO.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.SeekableIOExceptionpublic int readSync(ByteBuffer buffer) throws IOException
IO.ReadablereadSync in interface IO.Readablebuffer - buffer to fillIOExceptionpublic int readFullySync(long pos,
ByteBuffer buffer)
throws IOException
IO.Readable.SeekableIO.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.SeekableIOExceptionpublic int readFullySync(ByteBuffer buffer) throws IOException
IO.ReadablereadFullySync in interface IO.Readablebuffer - the buffer to fillIOExceptionpublic int readFully(byte[] buffer)
throws IOException
IO.ReadableByteStreamreadFully in interface IO.ReadableByteStreamIOExceptionpublic IAsync<IOException> canStartReading()
IO.ReadablecanStartReading in interface IO.ReadablecanStartReading in interface IO.ReadableByteStreampublic int readAsync()
throws IOException
IO.Readable.BufferedreadAsync in interface IO.Readable.BufferedIOExceptionpublic AsyncSupplier<Integer,IOException> readAsync(long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.Readable.SeekableIO.Readable.readAsync(ByteBuffer, Consumer) 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.Seekablepublic AsyncSupplier<Integer,IOException> readAsync(ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.ReadablereadAsync in interface IO.Readablebuffer - buffer to fillondone - called before the returned AsyncWork is unblocked and its listeners are called.public AsyncSupplier<ByteBuffer,IOException> readNextBufferAsync(Consumer<Pair<ByteBuffer,IOException>> ondone)
IO.Readable.BufferedreadNextBufferAsync in interface IO.Readable.Bufferedpublic ByteBuffer readNextBuffer() throws IOException
IO.Readable.BufferedreadNextBuffer in interface IO.Readable.BufferedIOExceptionpublic AsyncSupplier<Integer,IOException> readFullySyncIfPossible(ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.Readable.BufferedreadFullySyncIfPossible in interface IO.Readable.Bufferedpublic AsyncSupplier<Integer,IOException> readFullySyncIfPossible(long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
public AsyncSupplier<Integer,IOException> readFullyAsync(long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.Readable.SeekableIO.Readable.readFullyAsync(ByteBuffer, Consumer) 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.Seekablepublic AsyncSupplier<Integer,IOException> readFullyAsync(ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.ReadablereadFullyAsync in interface IO.Readablebuffer - the buffer to fillondone - called before the returned AsyncWork is unblocked and its listeners are called.public long skipSync(long n)
IO.ReadableskipSync in interface IO.Readablepublic int skip(int skip)
IO.ReadableByteStreamIO.Readable.skipSync(long) but limited to an integer.skip in interface IO.ReadableByteStreampublic AsyncSupplier<Long,IOException> skipAsync(long n, Consumer<Pair<Long,IOException>> ondone)
IO.ReadableskipAsync in interface IO.Readablepublic long seekSync(IO.Seekable.SeekType type, long move)
IO.SeekableseekSync in interface IO.Seekablepublic AsyncSupplier<Long,IOException> seekAsync(IO.Seekable.SeekType type, long move, Consumer<Pair<Long,IOException>> ondone)
IO.SeekableseekAsync in interface IO.SeekableCopyright © 2019. All rights reserved.