public class SimpleByteSource extends Object implements ByteSource
Each SimpleByteSource is associated with a `Stream<ByteBuffer>`. The read() method simply serves the ByteBuffers from the stream.
Actually, read() serves a readonly view of the original ByteBuffer from the stream. The original ByteBuffer is not modified, therefore can be shared by multiple SimpleByteSources.
Constructor and Description |
---|
SimpleByteSource(Stream<ByteBuffer> bbStream)
Create a SimpleByteSource based on the stream of ByteBuffers.
|
SimpleByteSource(ByteBuffer bb)
Create a SimpleByteSource based on a single ByteBuffer.
|
SimpleByteSource(byte[] bytes)
Create a SimpleByteSource of the bytes.
|
public SimpleByteSource(Stream<ByteBuffer> bbStream)
CAUTION: the stream must be non-blocking in yielding its elements, i.e. the tryAdvance() method of its spliterator must be non-blocking.
public SimpleByteSource(ByteBuffer bb)
Calling this constructor is equivalent to `new SimpleByteSource( Stream.of(bb) )`.
public SimpleByteSource(byte[] bytes)
Calling this constructor is equivalent to `new SimpleByteSource( ByteBuffer.wrap(bytes) )`.
public Async<ByteBuffer> read() throws IllegalStateException
This method will serve the next ByteBuffer from the stream. Actually, a readonly view is served, so that the original ByteBuffer will not be touched.
read
in interface ByteSource
IllegalStateException
- if this source is closed.public Async<Void> close()
close
in interface ByteSource