Package co.nstant.in.cbor
Class CborDecoder
- java.lang.Object
-
- co.nstant.in.cbor.CborDecoder
-
public class CborDecoder extends Object
Decoder for the CBOR format based.
-
-
Constructor Summary
Constructors Constructor Description CborDecoder(InputStream inputStream)Initialize a new decoder which reads the binary encoded data from anOutputStream.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<DataItem>decode()Decode theInputStreamto a list ofDataItems.static List<DataItem>decode(byte[] bytes)Convenience method to decode a byte array directly.voiddecode(DataItemListener dataItemListener)Streaming decoding of an input stream.DataItemdecodeNext()Decodes exactly one DataItem from the input stream.booleanisAutoDecodeInfinitiveArrays()booleanisAutoDecodeInfinitiveByteStrings()booleanisAutoDecodeInfinitiveMaps()booleanisAutoDecodeInfinitiveUnicodeStrings()booleanisAutoDecodeLanguageTaggedStrings()booleanisAutoDecodeRationalNumbers()booleanisRejectDuplicateKeys()voidsetAutoDecodeInfinitiveArrays(boolean autoDecodeInfinitiveArrays)voidsetAutoDecodeInfinitiveByteStrings(boolean autoDecodeInfinitiveByteStrings)voidsetAutoDecodeInfinitiveMaps(boolean autoDecodeInfinitiveMaps)voidsetAutoDecodeInfinitiveUnicodeStrings(boolean autoDecodeInfinitiveUnicodeStrings)voidsetAutoDecodeLanguageTaggedStrings(boolean autoDecodeLanguageTaggedStrings)voidsetAutoDecodeRationalNumbers(boolean autoDecodeRationalNumbers)voidsetMaxPreallocationSize(int maxSize)Sets the given amount of bytes as maximum preallocation limit for arrays in all decoders.voidsetRejectDuplicateKeys(boolean rejectDuplicateKeys)
-
-
-
Constructor Detail
-
CborDecoder
public CborDecoder(InputStream inputStream)
Initialize a new decoder which reads the binary encoded data from anOutputStream.- Parameters:
inputStream- theOutputStreamto read the data from
-
-
Method Detail
-
decode
public static List<DataItem> decode(byte[] bytes) throws CborException
Convenience method to decode a byte array directly.- Parameters:
bytes- the CBOR encoded data- Returns:
- a list of
DataItems - Throws:
CborException- if decoding failed
-
decode
public List<DataItem> decode() throws CborException
Decode theInputStreamto a list ofDataItems.- Returns:
- the list of
DataItems - Throws:
CborException- if decoding failed
-
decode
public void decode(DataItemListener dataItemListener) throws CborException
Streaming decoding of an input stream. On each decoded DataItem, the callback listener is invoked.- Parameters:
dataItemListener- the callback listener- Throws:
CborException- if decoding failed
-
decodeNext
public DataItem decodeNext() throws CborException
Decodes exactly one DataItem from the input stream.- Returns:
- a
DataItemor null if end of stream has reached. - Throws:
CborException- if decoding failed
-
isAutoDecodeInfinitiveArrays
public boolean isAutoDecodeInfinitiveArrays()
-
setAutoDecodeInfinitiveArrays
public void setAutoDecodeInfinitiveArrays(boolean autoDecodeInfinitiveArrays)
-
isAutoDecodeInfinitiveMaps
public boolean isAutoDecodeInfinitiveMaps()
-
setAutoDecodeInfinitiveMaps
public void setAutoDecodeInfinitiveMaps(boolean autoDecodeInfinitiveMaps)
-
isAutoDecodeInfinitiveByteStrings
public boolean isAutoDecodeInfinitiveByteStrings()
-
setAutoDecodeInfinitiveByteStrings
public void setAutoDecodeInfinitiveByteStrings(boolean autoDecodeInfinitiveByteStrings)
-
isAutoDecodeInfinitiveUnicodeStrings
public boolean isAutoDecodeInfinitiveUnicodeStrings()
-
setAutoDecodeInfinitiveUnicodeStrings
public void setAutoDecodeInfinitiveUnicodeStrings(boolean autoDecodeInfinitiveUnicodeStrings)
-
isAutoDecodeRationalNumbers
public boolean isAutoDecodeRationalNumbers()
-
setAutoDecodeRationalNumbers
public void setAutoDecodeRationalNumbers(boolean autoDecodeRationalNumbers)
-
isAutoDecodeLanguageTaggedStrings
public boolean isAutoDecodeLanguageTaggedStrings()
-
setAutoDecodeLanguageTaggedStrings
public void setAutoDecodeLanguageTaggedStrings(boolean autoDecodeLanguageTaggedStrings)
-
isRejectDuplicateKeys
public boolean isRejectDuplicateKeys()
-
setRejectDuplicateKeys
public void setRejectDuplicateKeys(boolean rejectDuplicateKeys)
-
setMaxPreallocationSize
public void setMaxPreallocationSize(int maxSize)
Sets the given amount of bytes as maximum preallocation limit for arrays in all decoders. This prevents OutOfMemory exceptions on malicious CBOR with forged fixed length items. Note that items may exceed the given size when the decoded data actually contains much data. This may be limited by using a limiting stream.- Parameters:
maxSize- Maximum number of bytes to preallocate in array-based items. Set to 0 to disable.
-
-