public interface DurableInput extends DataInput, Closeable, AutoCloseable
DataInput and ByteBuffer. Provides utility methods for writing Bifurcan-specific
values such as readVLQ() and readUVLQ(), as well as ways to slice out delimited blocks via
sliceBlock(BlockPrefix.BlockType) et al.
All instances of DurableInput are presumed to be thread-local. If you need to hold onto the instance for
future decoding, store the result of pool() and then call DurableInput.Pool.instance() when you want
to resume decoding.
| Modifier and Type | Interface and Description |
|---|---|
static class |
DurableInput.Bounds
Describes the slice window for a
DurableInput, which can be recursively followed to the root. |
static interface |
DurableInput.Pool
A means of generating thread-local
DurableInputs, which do not need to be explicitly released. |
| Modifier and Type | Method and Description |
|---|---|
default InputStream |
asInputStream() |
DurableInput.Bounds |
bounds() |
void |
close()
Closes the input, freeing any resources associated with it.
|
DurableInput |
duplicate() |
static DurableInput |
from(Iterable<DurableInput> inputs)
Constructs an input from the concatenation of one or more
inputs. |
default boolean |
hasRemaining() |
default String |
hexBytes() |
default io.lacuna.bifurcan.durable.BlockPrefix |
peekPrefix()
Reads but does not advance past the next block prefix.
|
DurableInput.Pool |
pool() |
long |
position() |
int |
read(ByteBuffer dst)
Copies as many byte as possible into
dst, and returns the number of bytes. |
default boolean |
readBoolean()
Reads and advances past the next byte, treating any non-zero value as
true. |
byte |
readByte()
Reads and advances past the next
int8 value. |
char |
readChar()
Reads and advances past the next
int16 value. |
double |
readDouble()
Reads and advances past the next
float64 value. |
float |
readFloat()
Reads and advances past the next
float32 value. |
default void |
readFully(byte[] b)
Copies bytes into
b, throwing an EOFException if there are not enough bytes to fill it. |
default void |
readFully(byte[] b,
int off,
int len)
Copies bytes into
b, starting at offset, throwing an EOFException if there are not len
bytes available. |
int |
readInt()
Reads and advances past the next
int32 value. |
default String |
readLine() |
long |
readLong()
Reads and advances past the next
int64 value. |
default io.lacuna.bifurcan.durable.BlockPrefix |
readPrefix()
Reads and advances past the next block prefix.
|
short |
readShort()
Reads and advances past the next
int16 value. |
default int |
readUnsignedByte()
Reads and advances past the next
uint8 value. |
default long |
readUnsignedInt()
Reads and advances past the next
uint32 value. |
default int |
readUnsignedShort()
Reads and advances past the next
uint16 value. |
default String |
readUTF() |
default long |
readUVLQ()
Reads and advances past the next unsigned variable-length quantity, which works as described here.
|
default long |
readVLQ()
Reads and advances past the next signed variable-length quantity, which uses the first bit to encode the sign, and
then works as described here.
|
long |
remaining() |
DurableInput |
seek(long position)
Updates the position of the input, and returns itself.
|
default long |
size() |
default long |
skipBlock()
Advances to the end of the block beginning at the current position.
|
default int |
skipBytes(int n)
Advances the position by
n bytes. |
default long |
skipBytes(long n)
Advances the position by
n bytes; |
DurableInput |
slice(long start,
long end) |
default DurableInput |
sliceBlock(io.lacuna.bifurcan.durable.BlockPrefix.BlockType type)
Returns an input representing the contents of a block beginning at the current position, and advances the position
to the end of that block.
|
default DurableInput |
sliceBytes(long bytes)
Returns an input representing the byte interval between
[position(), position() + bytes), and advances the
position by bytes. |
default DurableInput |
slicePrefixedBlock()
Returns an input representing a block (with the prefix included) beginning at the current position, and advances
the position to the end of that block.
|
static DurableInput from(Iterable<DurableInput> inputs)
inputs.DurableInput slice(long start, long end)
[start, end)default DurableInput sliceBytes(long bytes)
[position(), position() + bytes), and advances the
position by bytes.default DurableInput sliceBlock(io.lacuna.bifurcan.durable.BlockPrefix.BlockType type)
type provided, otherwise throws an
IllegalStateException.default DurableInput slicePrefixedBlock()
void close()
close in interface AutoCloseableclose in interface Closeabledefault String hexBytes()
hexdump style 16-byte wide hexadecimal table representation the complete contents of the inputDurableInput.Bounds bounds()
DurableInput duplicate()
DurableInput seek(long position)
long remaining()
DurableInput.Pool pool()
default boolean hasRemaining()
long position()
default long size()
int read(ByteBuffer dst)
dst, and returns the number of bytes.default void readFully(byte[] b)
throws EOFException
b, throwing an EOFException if there are not enough bytes to fill it.readFully in interface DataInputEOFExceptiondefault void readFully(byte[] b,
int off,
int len)
throws EOFException
b, starting at offset, throwing an EOFException if there are not len
bytes available.readFully in interface DataInputEOFExceptiondefault int skipBytes(int n)
n bytes.default long skipBytes(long n)
n bytes;byte readByte()
int8 value.short readShort()
int16 value.char readChar()
int16 value.int readInt()
int32 value.long readLong()
int64 value.float readFloat()
float32 value.double readDouble()
float64 value.readDouble in interface DataInputdefault long readVLQ()
default long readUVLQ()
default boolean readBoolean()
true.readBoolean in interface DataInputdefault int readUnsignedByte()
uint8 value.readUnsignedByte in interface DataInputdefault int readUnsignedShort()
uint16 value.readUnsignedShort in interface DataInputdefault long readUnsignedInt()
uint32 value.default String readLine()
readLine in interface DataInputUnsupportedOperationExceptiondefault io.lacuna.bifurcan.durable.BlockPrefix readPrefix()
default io.lacuna.bifurcan.durable.BlockPrefix peekPrefix()
default long skipBlock()
default InputStream asInputStream()
InputStream corresponding to this input