public class BDecoder extends Object
A b-encoded byte stream can represent byte arrays, numbers, lists and maps
(dictionaries). This class implements a decoder of such streams into
BEncodedValues.
Inspired by Snark's implementation.
| Constructor and Description |
|---|
BDecoder(InputStream in)
Initializes a new BDecoder.
|
| Modifier and Type | Method and Description |
|---|---|
BEncodedValue |
bdecode()
Gets the next indicator and returns either null when the stream
has ended or b-decodes the rest of the stream and returns the
appropriate BEValue encoded object.
|
static BEncodedValue |
bdecode(ByteBuffer data)
Decode a B-encoded byte buffer.
|
static BEncodedValue |
bdecode(InputStream in)
Decode a B-encoded stream.
|
BEncodedValue |
bdecodeBytes()
Returns the next b-encoded value on the stream and makes sure it is a
byte array.
|
BEncodedValue |
bdecodeList()
Returns the next b-encoded value on the stream and makes sure it is a
list.
|
BEncodedValue |
bdecodeMap()
Returns the next b-encoded value on the stream and makes sure it is a
map (dictionary).
|
BEncodedValue |
bdecodeNumber()
Returns the next b-encoded value on the stream and makes sure it is a
number.
|
public BDecoder(InputStream in)
Nothing is read from the given InputStream yet.
in - The input stream to read from.public static BEncodedValue bdecode(InputStream in) throws IOException
Automatically instantiates a new BDecoder for the provided input stream and decodes its root member.
in - The input stream to read from.IOExceptionpublic static BEncodedValue bdecode(ByteBuffer data) throws IOException
Automatically instantiates a new BDecoder for the provided buffer and decodes its root member.
data - The ByteBuffer to read from.IOExceptionpublic BEncodedValue bdecode() throws IOException
IOExceptionpublic BEncodedValue bdecodeBytes() throws IOException
InvalidBEncodingException - If it is not a b-encoded byte array.IOExceptionpublic BEncodedValue bdecodeNumber() throws IOException
InvalidBEncodingException - If it is not a number.IOExceptionpublic BEncodedValue bdecodeList() throws IOException
InvalidBEncodingException - If it is not a list.IOExceptionpublic BEncodedValue bdecodeMap() throws IOException
InvalidBEncodingException - If it is not a map.IOExceptionCopyright © 2016. All rights reserved.