Java Code Examples for com.fasterxml.jackson.core.io.NumberInput#inLongRange()

The following examples show how to use com.fasterxml.jackson.core.io.NumberInput#inLongRange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StdDateFormat.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected Date _parseDate(String dateStr, ParsePosition pos) throws ParseException
{
    if (looksLikeISO8601(dateStr)) { // also includes "plain"
        return parseAsISO8601(dateStr, pos);
    }
    // Also consider "stringified" simple time stamp
    int i = dateStr.length();
    while (--i >= 0) {
        char ch = dateStr.charAt(i);
        if (ch < '0' || ch > '9') {
            // 07-Aug-2013, tatu: And [databind#267] points out that negative numbers should also work
            if (i > 0 || ch != '-') {
                break;
            }
        }
    }
    if ((i < 0)
        // let's just assume negative numbers are fine (can't be RFC-1123 anyway); check length for positive
            && (dateStr.charAt(0) == '-' || NumberInput.inLongRange(dateStr, false))) {
        return _parseDateFromLong(dateStr, pos);
    }
    // Otherwise, fall back to using RFC 1123. NOTE: call will NOT throw, just returns `null`
    return parseAsRFC1123(dateStr, pos);
}
 
Example 2
Source File: ParserBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void _parseSlowInt(int expType) throws IOException
{
    String numStr = _textBuffer.contentsAsString();
    try {
        int len = _intLength;
        char[] buf = _textBuffer.getTextBuffer();
        int offset = _textBuffer.getTextOffset();
        if (_numberNegative) {
            ++offset;
        }
        // Some long cases still...
        if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
            // Probably faster to construct a String, call parse, than to use BigInteger
            _numberLong = Long.parseLong(numStr);
            _numTypesValid = NR_LONG;
        } else {
            // nope, need the heavy guns... (rare case)
            _numberBigInt = new BigInteger(numStr);
            _numTypesValid = NR_BIGINT;
        }
    } catch (NumberFormatException nex) {
        // Can this ever occur? Due to overflow, maybe?
        _wrapError("Malformed numeric value '"+numStr+"'", nex);
    }
}
 
Example 3
Source File: ParserBase.java    From openbd-core with GNU General Public License v3.0 6 votes vote down vote up
private void _parseSlowInt(int expType, char[] buf, int offset, int len) throws IOException
{
    String numStr = _textBuffer.contentsAsString();
    try {
        // [JACKSON-230] Some long cases still...
        if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
            // Probably faster to construct a String, call parse, than to use BigInteger
            _numberLong = Long.parseLong(numStr);
            _numTypesValid = NR_LONG;
        } else {
            // nope, need the heavy guns... (rare case)
            _numberBigInt = new BigInteger(numStr);
            _numTypesValid = NR_BIGINT;
        }
    } catch (NumberFormatException nex) {
        // Can this ever occur? Due to overflow, maybe?
        _wrapError("Malformed numeric value '"+numStr+"'", nex);
    }
}