use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.
the class BigNumbersTest method _testBigInteger.
private void _testBigInteger(BigInteger expValue) throws Exception {
final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream();
final CBORGenerator sourceGen = cborGenerator(sourceBytes);
sourceGen.writeNumber(expValue);
sourceGen.close();
// but verify that the original content can be parsed
CBORParser parser = cborParser(sourceBytes.toByteArray());
assertToken(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
assertEquals(expValue, parser.getBigIntegerValue());
// also, coercion to long at least
long expL = expValue.longValue();
assertEquals(expL, parser.getLongValue());
// and int, if feasible
if (expL >= Integer.MIN_VALUE && expL <= Integer.MAX_VALUE) {
assertEquals((int) expL, parser.getIntValue());
}
assertNull(parser.nextToken());
parser.close();
}
use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jans by JanssenProject.
the class AuthenticatorDataParser method getCborDataSize.
private long getCborDataSize(byte[] cosePublicKeyBuffer) {
long keySize = 0;
CBORParser parser = null;
try {
parser = dataMapperService.cborCreateParser(cosePublicKeyBuffer);
while (!parser.isClosed()) {
JsonToken t = parser.nextToken();
if (t.isStructEnd()) {
JsonLocation tocloc = parser.getTokenLocation();
keySize = tocloc.getByteOffset();
break;
}
}
} catch (IOException e) {
throw new Fido2RuntimeException(e.getMessage(), e);
} finally {
if (parser != null) {
try {
parser.close();
} catch (IOException e) {
log.error("Exception when closing a parser {}", e.getMessage());
}
}
}
return keySize;
}
Aggregations