public class RangedByteSource extends Object implements ByteSource
The `min` limit is inclusive. The `max` limit is exclusive.
For example, an origin source contains 10 bytes {b0, ..., b9}. The sub-range [min=3, max=8) will contain 5 bytes {b3, ..., b7}.
Both `min` and `max` can go beyond the range of the origin source. If the origin source contains 10 bytes, sub-range [3, Long.MAX_VALUE) is valid, containing 7 bytes; sub-range [10, 20) is also valid, containing 0 bytes.
This class uses the skip(n) method on the origin source.
Note that `origin.skip(n)` does not need to actually skip n bytes;
this class can skip the origin by read and discard bytes.
| Constructor and Description |
|---|
RangedByteSource(ByteSource origin,
long min,
long max)
Create a sub-range [min, max) of the origin source.
|
| Instance Methods | |
|---|---|
long |
getMin()
Get the min limit of the range.
|
long |
getMax()
Get the max limit of the range.
|
long |
skip(long n)
Try to skip forward `n` bytes.
|
Async<ByteBuffer> |
read()
Read the next chunk of bytes.
|
Async<Void> |
close()
Close this source.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitasString, asString, readAll, toSinkpublic RangedByteSource(ByteSource origin, long min, long max)
Required: 0<=min<=max.
Note that it is legal if max>=L or min>=L where L is the length of the origin source.
public long getMin()
public long getMax()
public long skip(long n)
throws IllegalArgumentException,
IllegalStateException
skip in interface ByteSourcen - number of bytes to skip; n >= 0.0 <= m <= n.IllegalStateException - if this source is closed.IllegalArgumentException - if n < 0.public Async<ByteBuffer> read() throws IllegalStateException
read in interface ByteSourceIllegalStateException - if this source is closed.public Async<Void> close()
close in interface ByteSource