public class CborDecoder extends Object
InputStream.| Constructor and Description |
|---|
CborDecoder(InputStream is)
Creates a new
CborDecoder instance. |
| Modifier and Type | Method and Description |
|---|---|
protected long |
expectIntegerType(int ib)
Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
|
CborType |
peekType()
Peeks in the input stream for the upcoming type.
|
long |
readArrayLength()
Prolog to reading an array value in CBOR format.
|
boolean |
readBoolean()
Reads a boolean value in CBOR format.
|
Object |
readBreak()
Reads a "break"/stop value in CBOR format.
|
byte[] |
readByteString()
Reads a byte string value in CBOR format.
|
long |
readByteStringLength()
Prolog to reading a byte string value in CBOR format.
|
double |
readDouble()
Reads a double-precision float value in CBOR format.
|
float |
readFloat()
Reads a single-precision float value in CBOR format.
|
double |
readHalfPrecisionFloat()
Reads a half-precision float value in CBOR format.
|
long |
readInt()
Reads a signed or unsigned integer value in CBOR format.
|
int |
readInt16()
Reads a signed or unsigned 16-bit integer value in CBOR format.
|
long |
readInt32()
Reads a signed or unsigned 32-bit integer value in CBOR format.
|
long |
readInt64()
Reads a signed or unsigned 64-bit integer value in CBOR format.
|
int |
readInt8()
Reads a signed or unsigned 8-bit integer value in CBOR format.
|
protected int |
readMajorType(int majorType)
Reads the next major type from the underlying input stream, and verifies whether it matches the given expectation.
|
protected void |
readMajorTypeExact(int majorType,
int subtype)
Reads the next major type from the underlying input stream, and verifies whether it matches the given expectations.
|
protected long |
readMajorTypeWithSize(int majorType)
Reads the next major type from the underlying input stream, verifies whether it matches the given expectation, and decodes the payload into a size.
|
long |
readMapLength()
Prolog to reading a map of key-value pairs in CBOR format.
|
Object |
readNull()
Reads a
null-value in CBOR format. |
byte |
readSimpleValue()
Reads a single byte value in CBOR format.
|
int |
readSmallInt()
Reads a signed or unsigned small (<= 23) integer value in CBOR format.
|
long |
readTag()
Reads a semantic tag value in CBOR format.
|
String |
readTextString()
Reads an UTF-8 encoded string value in CBOR format.
|
long |
readTextStringLength()
Prolog to reading an UTF-8 encoded string value in CBOR format.
|
protected long |
readUInt(int length,
boolean breakAllowed)
Reads an unsigned integer with a given length-indicator.
|
protected int |
readUInt16()
Reads an unsigned 16-bit integer value.
|
protected long |
readUInt32()
Reads an unsigned 32-bit integer value.
|
protected long |
readUInt64()
Reads an unsigned 64-bit integer value.
|
protected int |
readUInt8()
Reads an unsigned 8-bit integer value.
|
protected long |
readUIntExact(int expectedLength,
int length)
Reads an unsigned integer with a given length-indicator.
|
Object |
readUndefined()
Reads an undefined value in CBOR format.
|
public CborDecoder(InputStream is)
CborDecoder instance.is - the actual input stream to read the CBOR-encoded data from, cannot be null.protected long expectIntegerType(int ib)
throws IOException
ib - the the expected type-1 if the major type was an signed integer, or 0 otherwise.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.@Nullable public CborType peekType() throws IOException
null in case of an end-of-stream.IOException - in case of I/O problems reading the CBOR-type from the underlying input stream.public long readArrayLength()
throws IOException
-1 in case of infinite-length arrays.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public boolean readBoolean()
throws IOException
IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.@Nullable public Object readBreak() throws IOException
null.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public byte[] readByteString()
throws IOException
null. In case the encoded string has a length of 0, an empty string is returned.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public long readByteStringLength()
throws IOException
-1 in case of infinite-length strings.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public double readDouble()
throws IOException
Float.MIN_VALUE to Float.MAX_VALUE are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public float readFloat()
throws IOException
Float.MIN_VALUE to Float.MAX_VALUE are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public double readHalfPrecisionFloat()
throws IOException
Float.MIN_VALUE to Float.MAX_VALUE are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public long readInt()
throws IOException
Long.MIN_VALUE to Long.MAX_VALUE are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public int readInt16()
throws IOException
[-65536..65535] are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying output stream.public long readInt32()
throws IOException
[-4294967296..4294967295] are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying output stream.public long readInt64()
throws IOException
Long.MIN_VALUE to Long.MAX_VALUE are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying output stream.public int readInt8()
throws IOException
[-256..255] are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying output stream.protected int readMajorType(int majorType)
throws IOException
majorType - the expected major type, cannot be null (unchecked).IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.protected void readMajorTypeExact(int majorType,
int subtype)
throws IOException
majorType - the expected major type, cannot be null (unchecked);subtype - the expected subtype.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.protected long readMajorTypeWithSize(int majorType)
throws IOException
majorType - the expected major type, cannot be null (unchecked).-1 if an infinite-length type is read.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public long readMapLength()
throws IOException
IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.@Nullable public Object readNull() throws IOException
null-value in CBOR format.null.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public byte readSimpleValue()
throws IOException
IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public int readSmallInt()
throws IOException
[-24..23] are supported.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying output stream.public long readTag()
throws IOException
IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public String readTextString() throws IOException
null. In case the encoded string has a length of 0, an empty string is returned.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.public long readTextStringLength()
throws IOException
-1 in case of infinite-length strings.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.protected long readUInt(int length,
boolean breakAllowed)
throws IOException
length - the length indicator to use;breakAllowed - if break is allowed.IOException - in case of I/O problems reading the unsigned integer from the underlying input stream.protected int readUInt16()
throws IOException
Long.MIN_VALUE to Long.MAX_VALUE are supported.IOException - in case of I/O problems writing the CBOR-encoded value to the underlying output stream.protected long readUInt32()
throws IOException
Long.MIN_VALUE to Long.MAX_VALUE are supported.IOException - in case of I/O problems writing the CBOR-encoded value to the underlying output stream.protected long readUInt64()
throws IOException
Long.MIN_VALUE to Long.MAX_VALUE are supported.IOException - in case of I/O problems writing the CBOR-encoded value to the underlying output stream.protected int readUInt8()
throws IOException
Long.MIN_VALUE to Long.MAX_VALUE are supported.IOException - in case of I/O problems writing the CBOR-encoded value to the underlying output stream.protected long readUIntExact(int expectedLength,
int length)
throws IOException
expectedLength - the expected length;length - the length indicator to use;IOException - in case of I/O problems reading the unsigned integer from the underlying input stream.@Nullable public Object readUndefined() throws IOException
null.IOException - in case of I/O problems reading the CBOR-encoded value from the underlying input stream.