ByteBuffer.
This is mostly geared to reading Quic or HTTP/3 frames that are composed
of an aggregation of Variable Length Integers.
This class is not multi-thread safe.
The BuffersReader class is an abstract class with two concrete
implementations: SingleBufferReader and ListBuffersReader.
The SingleBufferReader presents a simple lightweight view of a single
ByteBuffer. Instances of SingleBufferReader can be created by
calling BuffersReader.;
The ListBuffersReader view can be created from a (possibly empty)
list of byte buffers. New byte buffers can be later added to the ListBuffersReader instance
as they become available. Once a frame has been fully received,
BuffersReader#release() or BuffersReader#getAndRelease(long) should
be called to forget and relinquish all bytes buffers up to the current
position of the BuffersReader.
Released buffers are removed from BuffersReader list, and the position
of the reader is reset to 0, allowing to read the next frame from the remaining
data.
| Modifier and Type | Class and Description |
|---|---|
| private static record | |
| public static class | BuffersReader.
A |
| public static class | BuffersReader.
A lightweight view allowing to see a |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract void | |
| public abstract byte | |
| public abstract byte | Returns: the byte at the given position in the readerthe position of the byte position)Reads the byte located at the given position in the reader. |
| public abstract List | Returns: a list ofByteBuffer containing the next
bytes of data, starting at the current position.the amount of bytes to read and move
to the returned list. bytes)Returns a list of |
| public boolean | Returns: true if the reader has remaining bytes to the readReturns true if the reader has remaining bytes to the read. |
| public abstract boolean | |
| public abstract long | |
| public static BuffersReader. | |
| public static BuffersReader. | Returns: aListBuffersReaderCreates a |
| public static BuffersReader. | Returns: aListBuffersReaderCreates a |
| public abstract long | |
| public abstract long | |
| public abstract void | |
| public abstract long | Returns: the cumulated amount of data that has been read in thisBuffersReader since its creationReturns the cumulated amount of data that has been read in this
|
| public abstract void | release()
Releases all the data that has been read, sets the reader's position to 0 and its limit to the amount of data remaining. |
| public long | Returns: the number of bytes that remain to readReturns the number of bytes that remain to read. |
| public static BuffersReader. | single(ByteBuffer
a byte buffer buffer)Creates a lightweight |
| BuffersReader | back to summary |
|---|---|
| public BuffersReader() | |
| clear | back to summary |
|---|---|
| public abstract void clear() Release all buffers held by this | |
| get | back to summary |
|---|---|
| public abstract byte get() Reads one byte from the reader. This method increase
the position by one. The semantic is similar to
| |
| get | back to summary |
|---|---|
| public abstract byte get(long position) Reads the byte located at the given position in the
reader. The semantic is similar to
| |
| getAndRelease | back to summary |
|---|---|
| public abstract List Returns a list of
| |
| hasRemaining | back to summary |
|---|---|
| public boolean hasRemaining() Returns true if the reader has remaining bytes to the read.
The semantic is similar to
| |
| isEmpty | back to summary |
|---|---|
| public abstract boolean isEmpty() Returns true if this
| |
| limit | back to summary |
|---|---|
| public abstract long limit() Returns the limit of the reader.
The semantic is similar to
| |
| list | back to summary |
|---|---|
| public static BuffersReader. Creates an empty
| |
| list | back to summary |
|---|---|
| public static BuffersReader. Creates a
| |
| list | back to summary |
|---|---|
| public static BuffersReader. Creates a
| |
| offset | back to summary |
|---|---|
| public abstract long offset() Returns The offset of this
| |
| position | back to summary |
|---|---|
| public abstract long position() Returns the current position of the reader.
The semantic is similar to
| |
| position | back to summary |
|---|---|
| public abstract void position(long newPosition) Sets the position of the reader.
The semantic is similar to
| |
| read | back to summary |
|---|---|
| public abstract long read() Returns the cumulated amount of data that has been read in this
| |
| release | back to summary |
|---|---|
| public abstract void release() Releases all the data that has been read, sets the reader's position to 0 and its limit to the amount of data remaining. | |
| remaining | back to summary |
|---|---|
| public long remaining() Returns the number of bytes that remain to read.
The semantic is similar to
| |
| single | back to summary |
|---|---|
| public static BuffersReader. Creates a lightweight
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ByteBuffer | |
| private final int | |
| private final int |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public ByteBuffer | |
| public final boolean | equals(Object o)
Implements abstract java. Indicates whether some other object is "equal to" this one. |
| public final int | |
| public int | |
| public int | |
| public final String | toString()
Implements abstract java. Returns a string representation of the record. |
| buffer | back to summary |
|---|---|
| private final ByteBuffer buffer Record Component accessed by buffer(). | |
| limit | back to summary |
|---|---|
| private final int limit Record Component accessed by limit(). | |
| offset | back to summary |
|---|---|
| private final int offset Record Component accessed by offset(). | |
| Buffer | back to summary |
|---|---|
| pack-priv Buffer(ByteBuffer buffer, int offset, int limit) | |
| Buffer | back to summary |
|---|---|
| pack-priv Buffer(ByteBuffer buffer) | |
| buffer | back to summary |
|---|---|
| public ByteBuffer buffer() Record Component getter of buffer. | |
| equals | back to summary |
|---|---|
| public final boolean equals(Object o) Implements abstract java. Doc from java. Indicates whether some other object is "equal to" this one. In addition
to the general contract of
R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
| |
| hashCode | back to summary |
|---|---|
| public final int hashCode() Implements abstract java. Doc from java. Returns a hash code value for the record.
Obeys the general contract of | |
| limit | back to summary |
|---|---|
| public int limit() Record Component getter of limit. | |
| offset | back to summary |
|---|---|
| public int offset() Record Component getter of offset. | |
| toString | back to summary |
|---|---|
| public final String toString() Implements abstract java. Doc from java. Returns a string representation of the record.
In accordance with the general contract of In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves. | |
BuffersReader that iterates over a list of ByteBuffers.
New ByteBuffers can be added at the end of list by calling
add(ByteBuffer) or addAll(List), which increases
the limit accordingly.
When released, the data prior to the current
position() is discarded, the position
and offset are reset to 0, and the
limit is set to the amount of remaining data.
A ListBuffersReader can be reused after being released.
If it still contains data, the offset will
be 0. Otherwise, the offset will be set to the position
of the first buffer added to the
ListBuffersReader.
| Modifier and Type | Field and Description |
|---|---|
| private final List | |
| private BuffersReader. | |
| private long | |
| private long | |
| private int | |
| private long | |
| private long | |
| private long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public BuffersReader. | |
| public BuffersReader. | Returns: this readera list of buffers)ByteBuffersAdds a list of byte buffers to this reader. |
| public void | clear()
Implements abstract jdk. Release all buffers held by this |
| private ByteBuffer | current(boolean
if true, calling this method
will throw throwIfUnderflow)BufferUnderflowException if
the position is past the limit.Returns the current |
| public byte | get()
Implements abstract jdk. Reads one byte from the reader. |
| public byte | get(long pos)
Implements abstract jdk. Reads the byte located at the given position in the reader. |
| public List | getAndRelease(long bytes)
Implements abstract jdk. Returns a list of |
| public boolean | isEmpty()
Implements abstract jdk. Returns true if this |
| public long | limit()
Implements abstract jdk. Returns the limit of the reader. |
| public long | offset()
Implements abstract jdk. Returns The offset of this |
| public long | position()
Implements abstract jdk. Returns the current position of the reader. |
| public void | position(long pos)
Implements abstract jdk. Sets the position of the reader. |
| public long | read()
Implements abstract jdk. Returns the cumulated amount of data that has been read in this
|
| public void | release()
Implements abstract jdk. Releases all the data that has been read, sets the reader's position to 0 and its limit to the amount of data remaining. |
| buffers | back to summary |
|---|---|
| private final List<BuffersReader. | |
| current | back to summary |
|---|---|
| private BuffersReader. | |
| currentOffset | back to summary |
|---|---|
| private long currentOffset | |
| limit | back to summary |
|---|---|
| private long limit | |
| nextIndex | back to summary |
|---|---|
| private int nextIndex | |
| position | back to summary |
|---|---|
| private long position | |
| readAndReleased | back to summary |
|---|---|
| private long readAndReleased | |
| start | back to summary |
|---|---|
| private long start | |
| ListBuffersReader | back to summary |
|---|---|
| pack-priv ListBuffersReader() | |
| add | back to summary |
|---|---|
| public BuffersReader. Adds a new API Note This class doesn't make defensive copies of the provided buffers, so the caller must not modify the buffer's position or limit after it's been added to the reader.
| |
| addAll | back to summary |
|---|---|
| public BuffersReader. Adds a list of byte buffers to this reader. This is equivalent to calling: ListBuffersReader reader = ...; for (var buffer : buffers) { reader.add(buffer); }
| |
| clear | back to summary |
|---|---|
| public void clear() Implements abstract jdk. Doc from jdk. Release all buffers held by this
| |
| current | back to summary |
|---|---|
| private ByteBuffer current(boolean throwIfUnderflow) Returns the current
| |
| get | back to summary |
|---|---|
| public byte get() Implements abstract jdk. Doc from jdk. Reads one byte from the reader. This method increase
the position by one. The semantic is similar to
| |
| get | back to summary |
|---|---|
| public byte get(long pos) Implements abstract jdk. Doc from jdk. Reads the byte located at the given position in the
reader. The semantic is similar to
| |
| getAndRelease | back to summary |
|---|---|
| public List Implements abstract jdk. Doc from jdk. Returns a list of
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements abstract jdk. Doc from jdk. Returns true if this
| |
| limit | back to summary |
|---|---|
| public long limit() Implements abstract jdk. Doc from jdk. Returns the limit of the reader.
The semantic is similar to
| |
| offset | back to summary |
|---|---|
| public long offset() Implements abstract jdk. Doc from jdk. Returns The offset of this
| |
| position | back to summary |
|---|---|
| public long position() Implements abstract jdk. Doc from jdk. Returns the current position of the reader.
The semantic is similar to
| |
| position | back to summary |
|---|---|
| public void position(long pos) Implements abstract jdk. Doc from jdk. Sets the position of the reader.
The semantic is similar to
| |
| read | back to summary |
|---|---|
| public long read() Implements abstract jdk. Doc from jdk. Returns the cumulated amount of data that has been read in this
| |
| release | back to summary |
|---|---|
| public void release() Implements abstract jdk. Doc from jdk. Releases all the data that has been read, sets the reader's position to 0 and its limit to the amount of data remaining.
| |
ByteBuffer as a
BuffersReader. This class wrap a single ByteBuffer
and cannot be reused after release().
| Modifier and Type | Field and Description |
|---|---|
| pack-priv long | |
| pack-priv ByteBuffer | |
| pack-priv long |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | clear()
Implements abstract jdk. Release all buffers held by this |
| public byte | get()
Implements abstract jdk. Reads one byte from the reader. |
| public byte | get(long position)
Implements abstract jdk. Reads the byte located at the given position in the reader. |
| public List | getAndRelease(long bytes)
Implements abstract jdk. Returns a list of |
| public ByteBuffer | Returns: a buffer containing the nextbytes.This method has the same semantics than |
| public boolean | hasRemaining()
Overrides jdk. Returns true if the reader has remaining bytes to the read. |
| public boolean | isEmpty()
Implements abstract jdk. Returns true if this |
| public long | limit()
Implements abstract jdk. Returns the limit of the reader. |
| public long | offset()
Implements abstract jdk. Returns The offset of this |
| public long | position()
Implements abstract jdk. Returns the current position of the reader. |
| public void | position(long pos)
Implements abstract jdk. Sets the position of the reader. |
| public long | read()
Implements abstract jdk. Returns the cumulated amount of data that has been read in this
|
| public void | release()
Implements abstract jdk. Releases all the data that has been read, sets the reader's position to 0 and its limit to the amount of data remaining. |
| read | back to summary |
|---|---|
| pack-priv long read | |
| single | back to summary |
|---|---|
| pack-priv ByteBuffer single | |
| start | back to summary |
|---|---|
| pack-priv long start | |
| SingleBufferReader | back to summary |
|---|---|
| pack-priv SingleBufferReader(ByteBuffer single) | |
| clear | back to summary |
|---|---|
| public void clear() Implements abstract jdk. Doc from jdk. Release all buffers held by this
| |
| get | back to summary |
|---|---|
| public byte get() Implements abstract jdk. Doc from jdk. Reads one byte from the reader. This method increase
the position by one. The semantic is similar to
| |
| get | back to summary |
|---|---|
| public byte get(long position) Implements abstract jdk. Doc from jdk. Reads the byte located at the given position in the
reader. The semantic is similar to
| |
| getAndRelease | back to summary |
|---|---|
| public List Implements abstract jdk. Doc from jdk. Returns a list of
| |
| getAndReleaseBuffer | back to summary |
|---|---|
| public ByteBuffer getAndReleaseBuffer(long bytes) This method has the same semantics than
| |
| hasRemaining | back to summary |
|---|---|
| public boolean hasRemaining() Overrides jdk. Doc from jdk. Returns true if the reader has remaining bytes to the read.
The semantic is similar to
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Implements abstract jdk. Doc from jdk. Returns true if this
| |
| limit | back to summary |
|---|---|
| public long limit() Implements abstract jdk. Doc from jdk. Returns the limit of the reader.
The semantic is similar to
| |
| offset | back to summary |
|---|---|
| public long offset() Implements abstract jdk. Doc from jdk. Returns The offset of this
| |
| position | back to summary |
|---|---|
| public long position() Implements abstract jdk. Doc from jdk. Returns the current position of the reader.
The semantic is similar to
| |
| position | back to summary |
|---|---|
| public void position(long pos) Implements abstract jdk. Doc from jdk. Sets the position of the reader.
The semantic is similar to
| |
| read | back to summary |
|---|---|
| public long read() Implements abstract jdk. Doc from jdk. Returns the cumulated amount of data that has been read in this
| |
| release | back to summary |
|---|---|
| public void release() Implements abstract jdk. Doc from jdk. Releases all the data that has been read, sets the reader's position to 0 and its limit to the amount of data remaining.
| |