|Constructor and Description|
Create a TextByteSource that encodes charSource to bytes.
Create a TextByteSource that encodes charSource to UTF-8 bytes.
Read the next chunk of bytes.
Close this source.
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public TextByteSource(int bufferSize, CharsetEncoder encoder, Stream<? extends CharSequence> charSource)
bufferSize- preferred buffer size for read()
encoder- for encoding chars to bytes. CAUTION: CharsetEncoder is stateful and cannot be shared; create a new CharsetEncoder for each new TextByteSource.
charSource- source of chars
public TextByteSource(CharSequence... charSource)
public Async<ByteBuffer> read() throws IllegalStateException
The method returns an `Async<ByteBuffer>` which eventually completes in 3 possible ways:
End, indicating EOF.
AsyncIterator.forEach( source::read, System.out::println ) .finally_( source::close );
The resulting ByteBuffer may contain any number of bytes. For example, it may be a view of
a huge ByteBuffer that's cached and shared.
You may use
PushbackByteSource to "unread".
The ownership of the ByteBuffer is transferred to the caller. The content of the ByteBuffer should be treated as read-only.
CAUTION: since ByteBuffer is stateful (even for methods like
a new ByteBuffer must be created for each read() action.
The implementation may create a view of a shared ByteBuffer through
The app should wait for this read() action to complete before it calls another method on this source.
This method can be called multiple times; only the first call is effective.
This method should not be invoked while a read() is pending;
if that's needed, see
ThreadSafeByteSource for a solution.
Since ByteSource is a read-only concept, close() should not have any
side effects that the caller cares about.
The caller is allowed to ignore the returned
(as if the method returns
The close() action should not fail; if some internal exception arises, it can be logged.
Most implementations return an immediate
even if there are still background cleanup tasks running.