Class CborEncoder
OutputStream.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidWrites the start of an indefinite-length array.voidwriteArrayStart(int length) Writes the start of a definite-length array.voidwriteBoolean(boolean value) Writes a boolean value in canonical CBOR format.voidWrites a "break" stop-value in canonical CBOR format.voidwriteByteString(byte[] bytes) Writes a byte string in canonical CBOR-format.voidWrites the start of an indefinite-length byte string.voidwriteDouble(double value) Writes a double-precision float value in canonical CBOR format.voidwriteFloat(float value) Writes a single-precision float value in canonical CBOR format.voidwriteHalfPrecisionFloat(float value) Writes a half-precision float value in canonical CBOR format.voidwriteInt(long value) Writes a signed or unsigned integer value in canonical CBOR format, that is, tries to encode it in a little bytes as possible..voidwriteInt16(int value) Writes a signed or unsigned 16-bit integer value in CBOR format.voidwriteInt32(long value) Writes a signed or unsigned 32-bit integer value in CBOR format.voidwriteInt64(long value) Writes a signed or unsigned 64-bit integer value in CBOR format.voidwriteInt8(int value) Writes a signed or unsigned 8-bit integer value in CBOR format.voidWrites the start of an indefinite-length map.voidwriteMapStart(int length) Writes the start of a finite-length map.voidWrites anullvalue in canonical CBOR format.protected voidwriteSimpleType(int majorType, int value) Encodes and writes the major type and value as a simple type.voidwriteSimpleValue(byte simpleValue) Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.voidwriteSmallInt(int value) Writes a signed or unsigned small (<= 23) integer value in CBOR format.protected voidwriteString(int majorType, byte[] bytes) Writes a byte string in canonical CBOR-format.voidwriteTag(long tag) Writes a semantic tag in canonical CBOR format.voidwriteTextString(String value) Writes an UTF-8 string in canonical CBOR-format.voidWrites the start of an indefinite-length UTF-8 string.protected voidwriteType(int majorType, long value) Encodes and writes the major type indicator with a given payload (length).protected voidwriteUInt(int mt, long value) Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.protected voidwriteUInt16(int mt, int value) Encodes and writes an unsigned 16-bit integer valueprotected voidwriteUInt32(int mt, int value) Encodes and writes an unsigned 32-bit integer valueprotected voidwriteUInt64(int mt, long value) Encodes and writes an unsigned 64-bit integer valueprotected voidwriteUInt8(int mt, int value) Encodes and writes an unsigned 8-bit integer valuevoidWrites an "undefined" value in canonical CBOR format.
-
Constructor Details
-
CborEncoder
Creates a newCborEncoderinstance.- Parameters:
os- the actual output stream to write the CBOR-encoded data to, cannot benull.
-
-
Method Details
-
writeArrayStart
Writes the start of an indefinite-length array.After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.
After all array elements are written, one should write a single break value to end the array, seewriteBreak().- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeArrayStart
Writes the start of a definite-length array.After calling this method, one is expected to write the given number of array elements, which can be of any type. No length checks are performed.
- Parameters:
length- the number of array elements to write, should >= 0.- Throws:
IllegalArgumentException- in case the given length was negative;IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeBoolean
Writes a boolean value in canonical CBOR format.- Parameters:
value- the boolean to write.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeBreak
Writes a "break" stop-value in canonical CBOR format.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeByteString
Writes a byte string in canonical CBOR-format.- Parameters:
value- the byte string to write, can benullin which case a byte-string of length 0 is written.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeByteStringStart
Writes the start of an indefinite-length byte string.After calling this method, one is expected to write the given number of string parts. No length checks are performed.
After all string parts are written, one should write a single break value to end the string, seewriteBreak().- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeDouble
Writes a double-precision float value in canonical CBOR format.- Parameters:
value- the value to write, values fromDouble.MIN_VALUEtoDouble.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeFloat
Writes a single-precision float value in canonical CBOR format.- Parameters:
value- the value to write, values fromFloat.MIN_VALUEtoFloat.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeHalfPrecisionFloat
Writes a half-precision float value in canonical CBOR format.- Parameters:
value- the value to write, values fromFloat.MIN_VALUEtoFloat.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeInt
Writes a signed or unsigned integer value in canonical CBOR format, that is, tries to encode it in a little bytes as possible..- Parameters:
value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeInt16
Writes a signed or unsigned 16-bit integer value in CBOR format.- Parameters:
value- the value to write, values from [-65536..65535] are supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeInt32
Writes a signed or unsigned 32-bit integer value in CBOR format.- Parameters:
value- the value to write, values in the range [-4294967296..4294967295] are supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeInt64
Writes a signed or unsigned 64-bit integer value in CBOR format.- Parameters:
value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeInt8
Writes a signed or unsigned 8-bit integer value in CBOR format.- Parameters:
value- the value to write, values in the range [-256..255] are supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeMapStart
Writes the start of an indefinite-length map.After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.
After all map entries are written, one should write a single break value to end the map, seewriteBreak().- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeMapStart
Writes the start of a finite-length map.After calling this method, one is expected to write any number of map entries, as separate key and value. Keys and values can both be of any type. No length checks are performed.
- Parameters:
length- the number of map entries to write, should >= 0.- Throws:
IllegalArgumentException- in case the given length was negative;IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeNull
Writes anullvalue in canonical CBOR format.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeSimpleValue
Writes a simple value, i.e., an "atom" or "constant" value in canonical CBOR format.- Parameters:
value- the (unsigned byte) value to write, values from 32 to 255 are supported (though not enforced).- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeSmallInt
Writes a signed or unsigned small (<= 23) integer value in CBOR format.- Parameters:
value- the value to write, values in the range [-24..23] are supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeTag
Writes a semantic tag in canonical CBOR format.- Parameters:
tag- the tag to write, should >= 0.- Throws:
IllegalArgumentException- in case the given tag was negative;IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeTextString
Writes an UTF-8 string in canonical CBOR-format.Note that this method is platform specific, as the given string value will be encoded in a byte array using the platform encoding! This means that the encoding must be standardized and known.
- Parameters:
value- the UTF-8 string to write, can benullin which case an UTF-8 string of length 0 is written.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeTextStringStart
Writes the start of an indefinite-length UTF-8 string.After calling this method, one is expected to write the given number of string parts. No length checks are performed.
After all string parts are written, one should write a single break value to end the string, seewriteBreak().- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeUndefined
Writes an "undefined" value in canonical CBOR format.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeSimpleType
Encodes and writes the major type and value as a simple type.- Parameters:
majorType- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values from [0..31] are supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeString
Writes a byte string in canonical CBOR-format.- Parameters:
majorType- the major type of the string, should be either 0x40 or 0x60;value- the byte string to write, can benullin which case a byte-string of length 0 is written.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeType
Encodes and writes the major type indicator with a given payload (length).- Parameters:
majorType- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeUInt
Encodes and writes an unsigned integer value, that is, tries to encode it in a little bytes as possible.- Parameters:
mt- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeUInt16
Encodes and writes an unsigned 16-bit integer value- Parameters:
mt- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeUInt32
Encodes and writes an unsigned 32-bit integer value- Parameters:
mt- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeUInt64
Encodes and writes an unsigned 64-bit integer value- Parameters:
mt- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-
writeUInt8
Encodes and writes an unsigned 8-bit integer value- Parameters:
mt- the major type of the value to write, denotes what semantics the written value has;value- the value to write, values fromLong.MIN_VALUEtoLong.MAX_VALUEare supported.- Throws:
IOException- in case of I/O problems writing the CBOR-encoded value to the underlying output stream.
-