public class PushbackByteSource extends Object implements ByteSource
`unread(bb)` stores `bb` internally to be served in the next `read()`. read() will remove the stored `bb`. skip() may also remove the stored `bb`.
At most one ByteBuffer can be stored at a time. Consecutive unread() calls are not supported.
Constructor and Description |
---|
PushbackByteSource(ByteSource origin)
Create a PushbackByteSource wrapper of the `origin` ByteSource.
|
Instance Methods | |
---|---|
void |
unread(ByteBuffer bb)
Unread `bb`.
|
Async<ByteBuffer> |
read()
Read the next chunk of bytes.
|
long |
skip(long n)
Try to skip forward `n` bytes.
|
Async<Void> |
close()
Close this source.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
asString, asString, readAll, toSink
public PushbackByteSource(ByteSource origin)
public void unread(ByteBuffer bb) throws IllegalStateException
`bb` is stored, to be served in then next read().
If there is already a ByteBuffer stored from a previous unread(), this method throws IllegalStateException.
IllegalStateException
- if there is already a ByteBuffer stored from a previous unread();
or if this source has been closed.public Async<ByteBuffer> read() throws IllegalStateException
If there is a `bb` stored from a previous unread(), it's removed, and this read() action succeeds immediately with that `bb`. Otherwise, this call is equivalent to `origin.read()`.
read
in interface ByteSource
IllegalStateException
- if this source is closed.public long skip(long n) throws IllegalArgumentException, IllegalStateException
If there is a `bb` stored from a previous unread(), its position may be adjusted, or it may be removed entirely.
skip
in interface ByteSource
n
- number of bytes to skip; n >= 0
.0 <= m <= n
.IllegalStateException
- if this source is closed.IllegalArgumentException
- if n < 0
.public Async<Void> close()
close
in interface ByteSource