public class ThreadSafeByteSource extends Object implements ByteSource
ByteSource is usually not thread-safe.
This class provides a thread-safe wrapper - it's safe to call read()/skip()/close()
on any thread at any time.
The main purpose of this class is to allow close() to be called on any thread at any time.
Particularly, close() can be invoked while a read() is pending (which is usually illegal for a ByteSource). The pending read will be cancelled by close().
However, it is still considered a programming error to invoke read()/skip() while a read() is pending. This class checks for such invocations and throws IllegalStateException.
|Constructor and Description|
Creates a thread-safe wrapper of the `origin` ByteSource.
Read the next chunk of bytes.
Try to skip forward `n` bytes.
Close this source.
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public ThreadSafeByteSource(ByteSource origin)
public Async<ByteBuffer> read() throws IllegalStateException
If this source is closed, this action fails with an
AsynchronousCloseException. Note: that means the returned Async
will be a failure; not that this method will throw the exception.
public long skip(long n) throws IllegalArgumentException, IllegalStateException
This method throws IllegalStateException if there is a read pending.