Package org.webpki.cbor
Class CBORUtil
java.lang.Object
org.webpki.cbor.CBORUtil
Utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]concatByteArrays(byte[]... listOfArrays) static CBORStringcreateDateTime(Instant instant, boolean millis, boolean utc) CreateDateTimeobject.static CBORObjectcreateEpochTime(Instant instant, boolean millis) CreateEpochTimeobject.static longreverseBits(long bits, int fieldWidth) static byte[]unsignedLongToByteArray(long value)
-
Method Details
-
createDateTime
CreateDateTimeobject.This method creates a date/time string in the ISO format described in section 5.6 of [RFC3339]. The string is subsequently wrapped in aCBORStringobject.If theinstantobject is not within the range"0000-01-01T00:00:00Z"to"9999-12-31T23:59:59Z", aCBORExceptionis thrown .Ifmillisistruethe date/time string will feature milliseconds (.nnn) as well.Sample code:CBORString iso = CBORUtil.createDateTime(Instant.now(), true, false);
System.out.println(iso.toString());
"2025-12-05T13:55:42.418+01:00"- Parameters:
instant- Time source object.millis-Ifmillisistrue, the milliseconds of theinstantobject will be featured in the created time object. Note: if the millisecond part of theinstantobject is zero,millisis considered to befalse.Ifmillisisfalse, the millisecond part of theinstantobject will not be used, but may after rounding, add a second to the created time object. Rounding is performed for milliseconds≥500, and always in the positive direction.utc-Ifutcistrue, theUTCtime zone (denoted by a terminatingZ) will be used, else the local time followed by theUTCoffset (±hh:mm) will be used.- Returns:
CBORString- Throws:
CBORException- See Also:
createEpochTime
CreateEpochTimeobject.This method creates an Epoch [TIME] time stamp.If theinstantobject is not within the range0("1970-01-01T00:00:00Z") to253402300799("9999-12-31T23:59:59Z"), aCBORExceptionis thrown.IfmillisistrueaCBORFloatobject holding seconds with a milliseconds fraction will be created, else aCBORIntobject holding seconds will be created.Sample code:CBORObject epoch = CBORUtil.createEpochTime(Instant.now(), false);
System.out.println(epoch.toString());
1764939916- Parameters:
instant- Time source object.millis-Ifmillisistrue, the milliseconds of theinstantobject will be featured in the created time object. Note: if the millisecond part of theinstantobject is zero,millisis considered to befalse.Ifmillisisfalse, the millisecond part of theinstantobject will not be used, but may after rounding, add a second to the created time object. Rounding is performed for milliseconds≥500, and always in the positive direction.- Returns:
CBORObject- Throws:
CBORException- See Also:
concatByteArrays
public static byte[] concatByteArrays(byte[]... listOfArrays) unsignedLongToByteArray
public static byte[] unsignedLongToByteArray(long value) reverseBits
public static long reverseBits(long bits, int fieldWidth)
-