src/main/java/com/cedarsoftware/util/io/JsonParser.java
private Number readNumber(int c) throws IOException
    {
        final FastPushbackReader in = input;
        final StringBuilder number = numBuf;
        number.setLength(0);
        number.appendCodePoint(c);
        boolean isFloat = false;
        
        if (JsonReader.isLenient() && (c == '-' || c == 'N' || c == 'I') ) {
            // Handle negativity.
            final boolean isNeg = (c == '-');
            if (isNeg) {
                // Advance to next character.
                c = input.read();
            }
            
            // Case "-Infinity", "Infinity" or "NaN".
            if (c == 'I') {
                // [Out of RFC 4627] accept NaN/Infinity values
                readToken("infinity");
                return (isNeg) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
            } else if ('N' == c) {
                // [Out of RFC 4627] accept NaN/Infinity values
                readToken("nan");
                return Double.NaN;
            } else {
                // Case this is a number but not "-Infinity", like "-2". We let the normal code process.
                input.unread('-');
            }
        }
        
        while (true)
        {
            c = in.read();
            if ((c >= '0' && c <= '9') || c == '-' || c == '+')
            {
                number.appendCodePoint(c);
            }
            else if (c == '.' || c == 'e' || c == 'E')
            {
                number.appendCodePoint(c);
                isFloat = true;
            }
            else if (c == -1)
            {
                break;
            }
            else
            {
                in.unread(c);
                break;
            }
        }

        try
        {
            if (isFloat)
            {   // Floating point number needed
                return Double.parseDouble(number.toString());
            }
            else
            {
                return Long.parseLong(number.toString());
            }
        }
        catch (Exception e)
        {
            return (Number) error("Invalid number: " + number, e);
        }
    }
private Number readNumber(int c) throws IOException
    {
        final FastPushbackReader in = input;
        final StringBuilder number = numBuf;
        number.setLength(0);
        number.appendCodePoint(c);
        boolean isFloat = false;
        
        if (JsonReader.isLenient() && (c == '-' || c == 'N' || c == 'I') ) {
            // Handle negativity.
            final boolean isNeg = (c == '-');
            if (isNeg) {
                // Advance to next character.
                c = input.read();
            }
            
            // Case "-Infinity", "Infinity" or "NaN".
            if (c == 'I') {
                // [Out of RFC 4627] accept NaN/Infinity values
                readToken("infinity");
                return (isNeg) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
            } else if ('N' == c) {
                // [Out of RFC 4627] accept NaN/Infinity values
                readToken("nan");
                return Double.NaN;
            } else {
                // Case this is a number but not "-Infinity", like "-2". We let the normal code process.
                input.unread('-');
            }
        }
        
        while (true)
        {
            c = in.read();
            if ((c >= '0' && c <= '9') || c == '-' || c == '+')
            {
                number.appendCodePoint(c);
            }
            else if (c == '.' || c == 'e' || c == 'E')
            {
                number.appendCodePoint(c);
                isFloat = true;
            }
            else if (c == -1)
            {
                break;
            }
            else
            {
                in.unread(c);
                break;
            }
        }

        try
        {
            if (isFloat)
            {   // Floating point number needed
                return Double.parseDouble(number.toString());
            }
            else
            {
                return Long.parseLong(number.toString());
            }
        }
        catch (Exception e)
        {
            return (Number) error("Invalid number: " + number, e);
        }
    }
Read a JSON number

@param c int a character representing the first digit of the number that
was already read.
@return a Number (a Long or a Double) depending on whether the number is
a decimal number or integer.  This choice allows all smaller types (Float, int, short, byte)
to be represented as well.
@throws IOException for stream errors or parsing errors.