Class CBORObject
- All Implemented Interfaces:
Cloneable,Comparable<CBORObject>
- Direct Known Subclasses:
CBORArray,CBORBigInt,CBORBoolean,CBORBytes,CBORFloat,CBORInt,CBORMap,CBORNonFinite,CBORNull,CBORSimple,CBORString,CBORTag
In this implementation "object" should be regarded as equivalent to the CBOR [RFC 8949] term, "data item".
-
Method Summary
Modifier and TypeMethodDescriptionvoidCheck CBOR object for unread data.clone()Create deep copy of CBOR object.intcompareTo(CBORObject object) Compare CBOR objects for magnitude.byte[]encode()Encode CBOR object.booleanCompare CBOR objects for equality.getArray()Get CBORarrayobject.Get CBORbigintvalue.booleanGet CBORboolvalue.byte[]getBytes()Get CBORbstrobject.Get ISOdate/timeobject.Get UNIXEpochtime object.doubleGet "extended" CBORfloat64value.floatGet CBORfloat16value.floatGet CBORfloat32value.doubleGet CBORfloat64value.intgetInt16()Get CBORintvalue.intgetInt32()Get CBORintvalue.longgetInt64()Get CBORintvalue.intgetInt8()Get CBORintvalue.getMap()Get CBORmapobject.intGet CBOR#7.n(simple) value.Get CBORtstrobject.getTag()Get CBORtagobject.intGet CBORuintvalue.longGet CBORuintvalue.longGet CBORuintvalue.intgetUint8()Get CBORuintvalue.inthashCode()Calculate hash code of CBOR object.booleanisNull()Check for CBORnull.scan()Scan CBOR object and mark it as read.toDiagnosticNotation(boolean prettyPrint) Render CBOR object in Diagnostic Notation.toString()Render CBOR object in a pretty-printed form.
-
Method Details
-
encode
public byte[] encode()Encode CBOR object.Note: this method always return CBOR data using Deterministic Encoding.
See also
CBORArray.encodeAsSequence().- Returns:
- CBOR encoded
byteArray
-
getBigInteger
Get CBORbigintvalue.This method requires that the object is a
CBORBigIntorCBORInt, otherwise aCBORExceptionis thrown.- Returns:
BigInteger- Throws:
CBORException
-
getInt64
public long getInt64()Get CBORintvalue.This method requires that the object is a
CBORIntand has a value ranging from-0x8000000000000000to0x7fffffffffffffff.- Returns:
long- Throws:
CBORException
-
getUint64
public long getUint64()Get CBORuintvalue.This method requires that the object is a
CBORIntand has a value ranging from0to0xffffffffffffffff.- Returns:
long- Throws:
CBORException
-
getInt32
public int getInt32()Get CBORintvalue.This method requires that the object is a
CBORIntand has a value ranging from-0x80000000to0x7fffffff.- Returns:
int- Throws:
CBORException
-
getUint32
public long getUint32()Get CBORuintvalue.This method requires that the object is a
CBORIntand has a value ranging from0to0xffffffff.- Returns:
long- Throws:
CBORException
-
getInt16
public int getInt16()Get CBORintvalue.This method requires that the object is a
CBORIntand has a value ranging from-0x8000to0x7fff.- Returns:
int- Throws:
CBORException
-
getUint16
public int getUint16()Get CBORuintvalue.This method requires that the object is a
CBORIntand has a value ranging from0to0xffff.- Returns:
int- Throws:
CBORException
-
getInt8
public int getInt8()Get CBORintvalue.This method requires that the object is a
CBORIntand has a value ranging from-0x80to0x7f.- Returns:
int- Throws:
CBORException
-
getUint8
public int getUint8()Get CBORuintvalue.This method requires that the object is a
CBORIntand has a value ranging from0to0xff.- Returns:
int- Throws:
CBORException
-
getExtendedFloat64
public double getExtendedFloat64()Get "extended" CBORfloat64value.Note that unlike
getFloat64(), this method also supports theDouble.NaN,Double.POSITIVE_INFINITY, andDouble.NEGATIVE_INFINITYnon-finite variants.This method requires that the object is a
CBORFloator aCBORNonFinite, otherwise aCBORExceptionis thrown.- Returns:
double- Throws:
CBORException- See Also:
-
getFloat64
public double getFloat64()Get CBORfloat64value.This method requires that the object is a
CBORFloat, otherwise aCBORExceptionis thrown.Unlike
getExtendedFloat64(), this method only accepts "regular" floating-point numbers. This makes it adapted for CBOR protocols that do not considerNaNorInfinityvalid items. That is, the latter cause aCBORExceptionto be thrown.- Returns:
double- Throws:
CBORException
-
getFloat32
public float getFloat32()Get CBORfloat32value.This method requires that the object is a
CBORFloatholding a 16 or 32-bitIEEE754value, otherwise aCBORExceptionis thrown.- Returns:
float- Throws:
CBORException
-
getFloat16
public float getFloat16()Get CBORfloat16value.This method requires that the object is a
CBORFloatholding a 16-bitIEEE754value, otherwise aCBORExceptionis thrown.- Returns:
float- Throws:
CBORException
-
getSimple
public int getSimple()Get CBOR#7.n(simple) value.This method requires that the object is a
CBORSimple, otherwise aCBORExceptionis thrown.- Returns:
int- Throws:
CBORException
-
getBoolean
public boolean getBoolean()Get CBORboolvalue.This method requires that the object is a
CBORBoolean, otherwise aCBORExceptionis thrown.- Returns:
boolean- Throws:
CBORException
-
isNull
public boolean isNull()Check for CBORnull.If the object is a
CBORNullthe call will returntrue, else it will returnfalse.Note that the object will only be considered as "read" (
checkForUnread()) if the object is aCBORNull.- Returns:
boolean
-
getString
Get CBORtstrobject.This method requires that the object is a
CBORString, otherwise aCBORExceptionis thrown.- Returns:
String- Throws:
CBORException
-
getEpochTime
Get UNIXEpochtime object.This method requires that the object is a
CBORIntorCBORFloat, otherwise aCBORExceptionis thrown.- Returns:
GregorianCalendar- Throws:
CBORException- See Also:
-
getDateTime
Get ISOdate/timeobject.This method requires that the object is a
CBORStringthat is compatible with ISO date/time [RFC 3339], otherwise aCBORExceptionis thrown.- Returns:
GregorianCalendar- Throws:
CBORExceptionIllegalArgumentException- See Also:
-
getBytes
public byte[] getBytes()Get CBORbstrobject.This method requires that the object is a
CBORBytes, otherwise aCBORExceptionis thrown.- Returns:
byteArray- Throws:
CBORException
-
getMap
Get CBORmapobject.This method requires that the object is a
CBORMap, otherwise aCBORExceptionis thrown.- Returns:
- CBOR
mapobject - Throws:
CBORException
-
getArray
Get CBORarrayobject.This method requires that the object is a
CBORArray, otherwise aCBORExceptionis thrown.- Returns:
- CBOR
arrayobject - Throws:
CBORException
-
getTag
Get CBORtagobject.This method requires that the object is a
CBORTag, otherwise aCBORExceptionis thrown.- Returns:
- CBOR
tagobject - Throws:
CBORException
-
scan
Scan CBOR object and mark it as read.This method sets the status of this object as well as to possible child objects to "read".
See alsocheckForUnread().- Returns:
this
-
checkForUnread
public void checkForUnread()Check CBOR object for unread data.Verifies that all objects from the current object including possible child objects have been read (through calling
See alsogetBytes()etc.), and throws aCBORExceptionif this is not the case.scan().- Throws:
CBORException
-
equals
Compare CBOR objects for equality.The result is
trueif and only if the argument is notnulland is aCBORObject, and the associated binary encodings (as provided byencode()) are equivalent. -
compareTo
Compare CBOR objects for magnitude.The comparison is based on the associated binary encodings as provided by
encode().- Specified by:
compareToin interfaceComparable<CBORObject>- Parameters:
object- Argument to compare with
-
hashCode
public int hashCode()Calculate hash code of CBOR object.The hash is calculated in the same way as for
String.hashCode(), using the output fromencode()as"s". -
toDiagnosticNotation
Render CBOR object in Diagnostic Notation.If the object (as well as possible child objects), conforms to the subset of data types supported by JSON, this method can also be used to generate JSON data.
- Parameters:
prettyPrint- Iftruewhite space is added to make the result easier to read. Iffalseelements are output without additional white space (=single line).
-
toString
Render CBOR object in a pretty-printed form.Equivalent to
toDiagnosticNotation(boolean)with the argument set totrue. -
clone
Create deep copy of CBOR object.Note that the copy is assumed to be "unread" (
checkForUnread()).
-