final class PeekSource extends java.lang.Object implements Source
Source
which peeks into an upstream BufferedSource
and allows reading and
expanding of the buffered data without consuming it. Does this by requesting additional data from
the upstream source if needed and copying out of the internal buffer of the upstream source if
possible.
This source also maintains a snapshot of the starting location of the upstream buffer which it
validates against on every read. If the upstream buffer is read from, this source will become
invalid and throw IllegalStateException
on any future reads.
Modifier and Type | Field and Description |
---|---|
private Buffer |
buffer |
private boolean |
closed |
private int |
expectedPos |
private Segment |
expectedSegment |
private long |
pos |
private BufferedSource |
upstream |
Constructor and Description |
---|
PeekSource(BufferedSource upstream) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this source and releases the resources held by this source.
|
long |
read(Buffer sink,
long byteCount)
Removes at least 1, and up to
byteCount bytes from this and appends
them to sink . |
Timeout |
timeout()
Returns the timeout for this source.
|
private final BufferedSource upstream
private final Buffer buffer
private Segment expectedSegment
private int expectedPos
private boolean closed
private long pos
PeekSource(BufferedSource upstream)
public long read(Buffer sink, long byteCount) throws java.io.IOException
Source
byteCount
bytes from this and appends
them to sink
. Returns the number of bytes read, or -1 if this
source is exhausted.public Timeout timeout()
Source
public void close() throws java.io.IOException
Source