protected JsonToken _handleCBOREOF() throws IOException { /* NOTE: here we can and should close input, release buffers, * since this is "hard" EOF, not a boundary imposed by * header token. */ _tagValue = -1; close(); return (_currToken = null); }
@Override public int nextIntValue(int defaultValue) throws IOException { if (nextToken() == JsonToken.VALUE_NUMBER_INT) { return getIntValue(); } return defaultValue; }
private final String _decodeLongerName(int len) throws IOException { // Do we have enough buffered content to read? if ((_inputEnd - _inputPtr) < len) { // or if not, could we read? if (len >= _inputBuffer.length) { // If not enough space, need handling similar to chunked _finishLongText(len); return _textBuffer.contentsAsString(); } _loadToHaveAtLeast(len); } String name = _findDecodedFromSymbols(len); if (name != null) { _inputPtr += len; return name; } name = _decodeShortName(len); return _addDecodedToSymbols(len, name); }
@Override public long nextLongValue(long defaultValue) throws IOException { if (nextToken() == JsonToken.VALUE_NUMBER_INT) { return getLongValue(); } return defaultValue; }
@Override public double getDoubleValue() throws IOException { if ((_numTypesValid & NR_DOUBLE) == 0) { if (_numTypesValid == NR_UNKNOWN) { _checkNumericValue(NR_DOUBLE); } if ((_numTypesValid & NR_DOUBLE) == 0) { convertNumberToDouble(); } } return _numberDouble; }
_skipIncomplete(); _currToken = _decodeFieldName(); return null; if (!loadMore()) { _handleCBOREOF(); return null; _tagValue = Integer.valueOf(_decodeTag(ch & 0x1F)); if (_inputPtr >= _inputEnd) { if (!loadMore()) { _handleCBOREOF(); return null; switch (lowBits - 24) { case 0: _numberInt = _decode8Bits(); break; case 1: _numberInt = _decode16Bits(); break; case 2: int v = _decode32Bits(); if (v < 0) { long l = (long) v; long l = _decode64Bits();
_numTypesValid = NR_UNKNOWN; if (_tokenIncomplete) { _skipIncomplete(); loadMoreGuaranteed(); _reportUnexpectedBreak(); _decodeNonStringName(ch); _currToken = JsonToken.FIELD_NAME; return getText(); name = ""; } else { name = _findDecodedFromSymbols(lenMarker); if (name != null) { _inputPtr += lenMarker; } else { name = _decodeShortName(lenMarker); name = _addDecodedToSymbols(lenMarker, name); final int actualLen = _decodeExplicitLength(lenMarker); if (actualLen < 0) { name = _decodeChunkedName(); } else { name = _decodeLongerName(actualLen); return (nextToken() == JsonToken.FIELD_NAME) ? getCurrentName() : null;
_skipIncomplete(); return (_currToken = _decodeFieldName()); if (!loadMore()) { return _handleCBOREOF(); _tagValue = Integer.valueOf(_decodeTag(ch & 0x1F)); if (_inputPtr >= _inputEnd) { if (!loadMore()) { return _handleCBOREOF(); switch (lowBits - 24) { case 0: _numberInt = _decode8Bits(); break; case 1: _numberInt = _decode16Bits(); break; case 2: int v = _decode32Bits(); if (v >= 0) { _numberInt = v; long l = _decode64Bits(); if (l >= 0L) { _numberLong = l; _numTypesValid = NR_LONG;
private final int _decodeTag(int lowBits) throws IOException { if (lowBits <= 23) { return lowBits; } switch (lowBits - 24) { case 0: return _decode8Bits(); case 1: return _decode16Bits(); case 2: return _decode32Bits(); case 3: // 16-Jan-2014, tatu: Technically legal, but nothing defined, so let's // only allow for cases where encoder is being wasteful... long l = _decode64Bits(); if (l < MIN_INT_L || l > MAX_INT_L) { _reportError("Illegal Tag value: "+l); } return (int) l; } throw _constructError("Invalid low bits for Tag token: 0x"+Integer.toHexString(lowBits)); }
_throwInternal(); _skipBytes(lowBits); _skipBytes(_decode8Bits()); break; case 25: _skipBytes(_decode16Bits()); break; case 26: _skipBytes(_decode32Bits()); break; case 27: // seriously? _skipBytesL(_decode64Bits()); break; case 31: _skipChunked(type); break; default: _invalidToken(_typeByte);
loadMoreGuaranteed(); throw _constructError("Mismatched chunk in chunked content: expected "+expectedType +" but encountered "+type); _skipBytes(lowBits); _skipBytes(_decode8Bits()); break; case 25: _skipBytes(_decode16Bits()); break; case 26: _skipBytes(_decode32Bits()); break; case 27: // seriously? _skipBytesL(_decode64Bits()); break; case 31: throw _constructError("Illegal chunked-length indicator within chunked-length value (type "+expectedType+")"); default: _invalidToken(_typeByte);
protected final JsonToken _decodeFieldName() throws IOException loadMoreGuaranteed(); return JsonToken.END_OBJECT; _reportUnexpectedBreak(); _decodeNonStringName(ch); return JsonToken.FIELD_NAME; name = ""; } else { name = _findDecodedFromSymbols(lenMarker); if (name != null) { _inputPtr += lenMarker; } else { name = _decodeShortName(lenMarker); name = _addDecodedToSymbols(lenMarker, name); final int actualLen = _decodeExplicitLength(lenMarker); if (actualLen < 0) { name = _decodeChunkedName(); } else { name = _decodeLongerName(actualLen);
/** * Method that handles initial token type recognition for token * that has to be either FIELD_NAME or END_OBJECT. */ protected final void _decodeNonStringName(int ch) throws IOException { final int type = ((ch >> 5) & 0x7); String name; if (type == CBORConstants.MAJOR_TYPE_INT_POS) { name = _numberToName(ch, false); } else if (type == CBORConstants.MAJOR_TYPE_INT_NEG) { name = _numberToName(ch, true); } else if (type == CBORConstants.MAJOR_TYPE_BYTES) { /* 08-Sep-2014, tatu: As per [Issue#5], there are codecs * (f.ex. Perl module "CBOR::XS") that use Binary data... */ final int blen = _decodeExplicitLength(ch & 0x1F); byte[] b = _finishBytes(blen); // TODO: Optimize, if this becomes commonly used & bottleneck; we have // more optimized UTF-8 codecs available. name = new String(b, UTF8); } else { if ((ch & 0xFF) == CBORConstants.INT_BREAK) { _reportUnexpectedBreak(); } throw _constructError("Unsupported major type ("+type+") for CBOR Objects, not (yet?) supported, only Strings"); } _parsingContext.setCurrentName(name); }
_reportError("Unexpected array size ("+len+") for tagged 'bigfloat' value; should have exactly 2 number elements"); JsonToken t = nextToken(); _reportError("Unexpected token ("+t+") as the first part of 'bigfloat' value: should get VALUE_NUMBER_INT"); int exp = getIntValue(); t = nextToken(); _reportError("Unexpected token ("+t+") as the second part of 'bigfloat' value: should get VALUE_NUMBER_INT"); NumberType numberType = getNumberType(); if (numberType == NumberType.BIG_INTEGER) { dec = new BigDecimal(getBigIntegerValue(), exp); } else { dec = BigDecimal.valueOf(getLongValue(), exp); t = nextToken(); if (t != JsonToken.END_ARRAY) { _reportError("Unexpected token ("+t+") after 2 elements of 'bigfloat' value");
_numTypesValid = NR_UNKNOWN; if (_tokenIncomplete) { _skipIncomplete(); return (nextToken() == JsonToken.FIELD_NAME) && str.getValue().equals(getCurrentName());
private int _decodeChunkLength(int expType) throws IOException { if (_inputPtr >= _inputEnd) { loadMoreGuaranteed(); } int ch = (int) _inputBuffer[_inputPtr++] & 0xFF; if (ch == CBORConstants.INT_BREAK) { return -1; } int type = (ch >> 5); if (type != expType) { throw _constructError("Mismatched chunk in chunked content: expected " +expType+" but encountered "+type+" (byte 0x"+Integer.toHexString(ch)+")"); } int len = _decodeExplicitLength(ch & 0x1F); if (len < 0) { throw _constructError("Illegal chunked-length indicator within chunked-length value (type "+expType+")"); } return len; }
try { parser = dataMapperService.cborCreateParser(cosePublicKeyBuffer); while (!parser.isClosed()) { JsonToken t = parser.nextToken(); JsonLocation tocloc = parser.getTokenLocation(); if (t.isStructEnd()) { keySize = tocloc.getByteOffset(); if (parser != null) { try { parser.close(); } catch (IOException e) { log.info("exception when closing a parser {}", e.getMessage());
@Override public long getLongValue() throws IOException { if ((_numTypesValid & NR_LONG) == 0) { if (_numTypesValid == NR_UNKNOWN) { _checkNumericValue(NR_LONG); } if ((_numTypesValid & NR_LONG) == 0) { convertNumberToLong(); } } return _numberLong; }
@Override public BigDecimal getDecimalValue() throws IOException { if ((_numTypesValid & NR_BIGDECIMAL) == 0) { if (_numTypesValid == NR_UNKNOWN) { _checkNumericValue(NR_BIGDECIMAL); } if ((_numTypesValid & NR_BIGDECIMAL) == 0) { convertNumberToBigDecimal(); } } return _numberBigDecimal; }
@Override public int getIntValue() throws IOException { if ((_numTypesValid & NR_INT) == 0) { if (_numTypesValid == NR_UNKNOWN) { // not parsed at all _checkNumericValue(NR_INT); // will also check event type } if ((_numTypesValid & NR_INT) == 0) { // wasn't an int natively? convertNumberToInt(); // let's make it so, if possible } } return _numberInt; }