protected void reportUnexpectedNumberChar(int ch, String comment) throws JsonParseException { String msg = "Unexpected character ("+_getCharDesc(ch)+") in numeric value"; if (comment != null) { msg += ": "+comment; } _reportError(msg); }
public BigDecimal getDecimalValue() throws IOException, JsonParseException { if ((mNumTypesValid & NR_BIGDECIMAL) == 0) { if (mNumTypesValid == NR_UNKNOWN) { parseNumericValue(NR_BIGDECIMAL); } if ((mNumTypesValid & NR_BIGDECIMAL) == 0) { convertNumberToBigDecimal(); } } return mNumberBigDecimal; }
public double getDoubleValue() throws IOException, JsonParseException { if ((mNumTypesValid & NR_DOUBLE) == 0) { if (mNumTypesValid == NR_UNKNOWN) { parseNumericValue(NR_DOUBLE); } if ((mNumTypesValid & NR_DOUBLE) == 0) { convertNumberToDouble(); } } return mNumberDouble; }
protected void reportOverflowInt() throws IOException, JsonParseException { _reportError("Numeric value ("+getText()+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")"); }
protected void convertNumberToInt() throws IOException, JsonParseException { // First, converting from long ought to be easy if ((mNumTypesValid & NR_LONG) != 0) { // Let's verify it's lossless conversion by simple roundtrip int result = (int) mNumberLong; if (((long) result) != mNumberLong) { _reportError("Numeric value ("+getText()+") out of range of int"); } mNumberInt = result; } else if ((mNumTypesValid & NR_DOUBLE) != 0) { // Need to check boundaries if (mNumberDouble < MIN_INT_D || mNumberDouble > MAX_INT_D) { reportOverflowInt(); } mNumberInt = (int) mNumberDouble; } else if ((mNumTypesValid & NR_BIGDECIMAL) != 0) { if (BD_MIN_INT.compareTo(mNumberBigDecimal) > 0 || BD_MAX_INT.compareTo(mNumberBigDecimal) < 0) { reportOverflowInt(); } mNumberInt = mNumberBigDecimal.intValue(); } else { _throwInternal(); // should never get here } mNumTypesValid |= NR_INT; }
protected void convertNumberToBigDecimal() throws IOException, JsonParseException { /* 05-Aug-2008, tatus: Important note: this MUST start with * more accurate representations, since we don't know which * value is the original one (others get generated when * requested) */ if ((mNumTypesValid & NR_DOUBLE) != 0) { /* Let's actually parse from String representation, * to avoid rounding errors that non-decimal floating operations * would incur */ mNumberBigDecimal = new BigDecimal(getText()); } else if ((mNumTypesValid & NR_LONG) != 0) { mNumberBigDecimal = BigDecimal.valueOf(mNumberLong); } else if ((mNumTypesValid & NR_INT) != 0) { mNumberBigDecimal = BigDecimal.valueOf((long) mNumberInt); } else { _throwInternal(); // should never get here } mNumTypesValid |= NR_BIGDECIMAL; }
protected void convertNumberToLong() throws IOException, JsonParseException { if ((mNumTypesValid & NR_INT) != 0) { mNumberLong = (long) mNumberInt; } else if ((mNumTypesValid & NR_DOUBLE) != 0) { // Need to check boundaries if (mNumberDouble < MIN_LONG_D || mNumberDouble > MAX_LONG_D) { reportOverflowLong(); } mNumberLong = (long) mNumberDouble; } else if ((mNumTypesValid & NR_BIGDECIMAL) != 0) { if (BD_MIN_LONG.compareTo(mNumberBigDecimal) > 0 || BD_MAX_LONG.compareTo(mNumberBigDecimal) < 0) { reportOverflowLong(); } mNumberLong = mNumberBigDecimal.longValue(); } else { _throwInternal(); // should never get here } mNumTypesValid |= NR_LONG; }
public int getIntValue() throws IOException, JsonParseException { if ((mNumTypesValid & NR_INT) == 0) { if (mNumTypesValid == NR_UNKNOWN) { // not parsed at all parseNumericValue(NR_INT); // will also check event type } if ((mNumTypesValid & NR_INT) == 0) { // wasn't an int natively? convertNumberToInt(); // let's make it so, if possible } } return mNumberInt; }
public long getLongValue() throws IOException, JsonParseException { if ((mNumTypesValid & NR_LONG) == 0) { if (mNumTypesValid == NR_UNKNOWN) { parseNumericValue(NR_LONG); } if ((mNumTypesValid & NR_LONG) == 0) { convertNumberToLong(); } } return mNumberLong; }
_reportError("Current token ("+_currToken+") not numeric, can not use numeric value accessors"); _wrapError("Malformed numeric value '"+_textBuffer.contentsAsString()+"'", nex);
parseNumericValue(NR_UNKNOWN); // will also check event type _throwInternal();
/** * Method called to release internal buffers owned by the base * reader. This may be called along with {@link #_closeInput} (for * example, when explicitly closing this reader instance), or * separately (if need be). */ @Override protected void _releaseBuffers() throws IOException { super._releaseBuffers(); if (_bufferRecyclable) { byte[] buf = _inputBuffer; if (buf != null) { _inputBuffer = null; _ioContext.releaseReadIOBuffer(buf); } } } }
@Override public int getIntValue() throws IOException, JsonParseException { if ((_numTypesValid & NR_INT) == 0) { if (_numTypesValid == NR_UNKNOWN) { // not parsed at all _parseNumericValue(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; }
@Override public BigDecimal getDecimalValue() throws IOException, JsonParseException { if ((_numTypesValid & NR_BIGDECIMAL) == 0) { if (_numTypesValid == NR_UNKNOWN) { _parseNumericValue(NR_BIGDECIMAL); } if ((_numTypesValid & NR_BIGDECIMAL) == 0) { convertNumberToBigDecimal(); } } return _numberBigDecimal; }
@Override public long getLongValue() throws IOException, JsonParseException { if ((_numTypesValid & NR_LONG) == 0) { if (_numTypesValid == NR_UNKNOWN) { _parseNumericValue(NR_LONG); } if ((_numTypesValid & NR_LONG) == 0) { convertNumberToLong(); } } return _numberLong; }
return; _parseSlowIntValue(expType, buf, offset, len); return; _parseSlowFloatValue(expType); return; _reportError("Current token ("+_currToken+") not numeric, can not use numeric value accessors");
@Override public double getDoubleValue() throws IOException, JsonParseException { if ((_numTypesValid & NR_DOUBLE) == 0) { if (_numTypesValid == NR_UNKNOWN) { _parseNumericValue(NR_DOUBLE); } if ((_numTypesValid & NR_DOUBLE) == 0) { convertNumberToDouble(); } } return _numberDouble; }
protected void convertNumberToDouble() throws IOException, JsonParseException { /* 05-Aug-2008, tatus: Important note: this MUST start with * more accurate representations, since we don't know which * value is the original one (others get generated when * requested) */ if ((mNumTypesValid & NR_BIGDECIMAL) != 0) { mNumberDouble = mNumberBigDecimal.doubleValue(); } else if ((mNumTypesValid & NR_LONG) != 0) { mNumberDouble = (double) mNumberLong; } else if ((mNumTypesValid & NR_INT) != 0) { mNumberDouble = (double) mNumberInt; } else { _throwInternal(); // should never get here } mNumTypesValid |= NR_DOUBLE; }
_parseNumericValue(NR_UNKNOWN); // will also check event type _throwInternal();
protected void reportInvalidNumber(String msg) throws JsonParseException { _reportError("Invalid numeric value: "+msg); }