public class ByteArrayIO extends AbstractIO implements IO.Readable.Buffered, IO.Readable.Seekable, IO.Writable.Seekable, IO.Writable.Buffered, IO.KnownSize, IO.Resizable
IO.Readable.Buffered, IO.Readable.SeekableIO.Seekable.SeekTypeIO.Writable.Buffered, IO.Writable.Seekabledescription, priority| Constructor and Description |
|---|
ByteArrayIO(byte[] data,
int bytesUsed,
String description)
Constructor.
|
ByteArrayIO(byte[] data,
String description)
Constructor.
|
ByteArrayIO(int initialSize,
String description)
Constructor.
|
ByteArrayIO(String description)
Constructor with initial buffer size of 4096.
|
| Modifier and Type | Method and Description |
|---|---|
IAsync<IOException> |
canStartReading()
Return a synchronization point that is unblocked when data is ready to be read.
|
IAsync<IOException> |
canStartWriting()
Return a synchronization point that is unblocked when data is ready to be written.
|
protected void |
closeResources(Async<IOException> ondone) |
protected IAsync<IOException> |
closeUnderlyingResources() |
IAsync<IOException> |
flush()
Force to write buffered data to the underlying IO.
|
byte[] |
getArray() |
String |
getAsString(Charset charset)
Convert the content of the buffer into a String encoded with the given charset.
|
int |
getCapacity() |
long |
getPosition()
Return the current position.
|
AsyncSupplier<Long,IOException> |
getSizeAsync()
Asynchronous operation to get the size of the IO.
|
long |
getSizeSync()
Synchronous operation to get the size of the IO.
|
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.
|
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. |
byte |
readByte()
Similar to read, but returns a byte and throw an EOFException in case the end is reached.
|
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.
|
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.
|
AsyncSupplier<Void,IOException> |
setSizeAsync(long newSize)
Asynchronous resize.
|
void |
setSizeSync(long newSize)
Synchronous resize.
|
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.
|
ByteBuffer |
toByteBuffer()
Wrap the buffer into a ByteBuffer.
|
void |
write(byte b)
Write a byte.
|
void |
write(byte[] buffer,
int offset,
int len)
Write bytes from the given buffer.
|
AsyncSupplier<Integer,IOException> |
writeAsync(ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Write asynchronously all bytes available in the given buffer at the current position.
|
AsyncSupplier<Integer,IOException> |
writeAsync(long pos,
ByteBuffer buffer,
Consumer<Pair<Integer,IOException>> ondone)
Same as
IO.Writable.writeAsync(ByteBuffer, Consumer) but at the given position. |
int |
writeSync(ByteBuffer buffer)
Write synchronously all bytes available in the given buffer at the current position.
|
int |
writeSync(long pos,
ByteBuffer buffer)
Same as
IO.Writable.writeSync(ByteBuffer) but at the given position. |
getPriority, getSourceDescription, setPriorityaddCloseListener, addCloseListener, close, closeAsync, isClosed, isClosing, lockClose, operation, operation, removeCloseListener, removeCloseListener, unlockCloseclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitreadFullySyncIfPossible, readNextBufferAsyncreadAsync, readFullyAsyncreadAsync, readFullyAsync, skipAsyncwriteAsyncseekAsyncwriteAsyncwritepublic ByteArrayIO(String description)
public ByteArrayIO(int initialSize,
String description)
public ByteArrayIO(byte[] data,
String description)
public ByteArrayIO(byte[] data,
int bytesUsed,
String description)
public TaskManager getTaskManager()
IOgetTaskManager in interface IOpublic IO getWrappedIO()
IOgetWrappedIO in interface IOprotected IAsync<IOException> closeUnderlyingResources()
closeUnderlyingResources in class ConcurrentCloseable<IOException>protected void closeResources(Async<IOException> ondone)
closeResources in class ConcurrentCloseable<IOException>public IAsync<IOException> canStartReading()
IO.ReadablecanStartReading in interface IO.ReadablecanStartReading in interface IO.ReadableByteStreampublic IAsync<IOException> canStartWriting()
IO.WritablecanStartWriting in interface IO.WritablecanStartWriting in interface IO.WritableByteStreampublic long getPosition()
IO.PositionKnowngetPosition in interface IO.PositionKnownpublic long getSizeSync()
IO.KnownSizegetSizeSync in interface IO.KnownSizepublic AsyncSupplier<Long,IOException> getSizeAsync()
IO.KnownSizegetSizeAsync in interface IO.KnownSizepublic int read()
IO.ReadableByteStreamread in interface IO.ReadableByteStreampublic int read(byte[] buffer,
int offset,
int len)
IO.ReadableByteStreamread in interface IO.ReadableByteStreampublic byte readByte()
throws EOFException
IO.ReadableByteStreamreadByte in interface IO.ReadableByteStreamEOFExceptionpublic int readFully(byte[] buffer)
IO.ReadableByteStreamreadFully in interface IO.ReadableByteStreampublic int readFullySync(ByteBuffer buffer)
IO.ReadablereadFullySync in interface IO.Readablebuffer - the buffer to fillpublic int readFullySync(long pos,
ByteBuffer buffer)
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.Seekablepublic int readSync(ByteBuffer buffer)
IO.ReadablereadSync in interface IO.Readablebuffer - buffer to fillpublic int readSync(long pos,
ByteBuffer buffer)
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.Seekablepublic AsyncSupplier<Integer,IOException> readFullySyncIfPossible(ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.Readable.BufferedreadFullySyncIfPossible in interface IO.Readable.Bufferedpublic int readAsync()
IO.Readable.BufferedreadAsync in interface IO.Readable.Bufferedpublic 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<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> 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 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<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 String getAsString(Charset charset)
public void write(byte b)
IO.WritableByteStreamwrite in interface IO.WritableByteStreampublic void write(byte[] buffer,
int offset,
int len)
IO.WritableByteStreamwrite in interface IO.WritableByteStreampublic int writeSync(ByteBuffer buffer)
IO.WritablewriteSync in interface IO.Writablepublic int writeSync(long pos,
ByteBuffer buffer)
IO.Writable.SeekableIO.Writable.writeSync(ByteBuffer) but at the given position.
Note that if the IO implements Resizable, the behaviour is different when writing at
the end or beyond the end of the IO: if not resizable, it must throw an exception,
while a resizable IO should accept it except if the resize operation fails.writeSync in interface IO.Writable.Seekablepublic AsyncSupplier<Integer,IOException> writeAsync(ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.WritablewriteAsync in interface IO.Writablepublic AsyncSupplier<Integer,IOException> writeAsync(long pos, ByteBuffer buffer, Consumer<Pair<Integer,IOException>> ondone)
IO.Writable.SeekableIO.Writable.writeAsync(ByteBuffer, Consumer) but at the given position.
Note that if the IO implements Resizable, the behaviour is different when writing at
the end or beyond the end of the IO: if not resizable, it must throw an exception,
while a resizable IO should accept it except if the resize operation fails.writeAsync in interface IO.Writable.Seekablepublic void setSizeSync(long newSize)
IO.ResizablesetSizeSync in interface IO.Resizablepublic AsyncSupplier<Void,IOException> setSizeAsync(long newSize)
IO.ResizablesetSizeAsync in interface IO.Resizablepublic 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.Seekablepublic int skip(int skip)
IO.ReadableByteStreamIO.Readable.skipSync(long) but limited to an integer.skip in interface IO.ReadableByteStreampublic long skipSync(long n)
IO.ReadableskipSync in interface IO.Readablepublic AsyncSupplier<Long,IOException> skipAsync(long n, Consumer<Pair<Long,IOException>> ondone)
IO.ReadableskipAsync in interface IO.Readablepublic byte[] getArray()
public int getCapacity()
public ByteBuffer toByteBuffer()
public IAsync<IOException> flush()
IO.Writable.Bufferedflush in interface IO.Writable.BufferedCopyright © 2019. All rights reserved.