Ignore:
Timestamp:
2017-12-23T02:40:43+01:00 (8 years ago)
Author:
Don-vip
Message:

see #15682 - upgrade to JSR 374 (JSON Processing) API 1.1.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/glassfish/json/JsonTokenizer.java

    r6756 r13231  
    22 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
    33 *
    4  * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
     4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved.
    55 *
    66 * The contents of this file are subject to the terms of either the GNU
     
    99 * may not use this file except in compliance with the License.  You can
    1010 * obtain a copy of the License at
    11  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
    12  * or packager/legal/LICENSE.txt.  See the License for the specific
     11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
     12 * or LICENSE.txt.  See the License for the specific
    1313 * language governing permissions and limitations under the License.
    1414 *
    1515 * When distributing the software, include this License Header Notice in each
    16  * file and include the License file at packager/legal/LICENSE.txt.
     16 * file and include the License file at LICENSE.txt.
    1717 *
    1818 * GPL Classpath Exception:
     
    293293            }
    294294        }
    295         readBegin--;
    296         storeEnd = readBegin;
     295        if (ch != -1) {
     296            // Only reset readBegin if eof has not been reached
     297            readBegin--;
     298            storeEnd = readBegin;
     299        }
    297300    }
    298301
     
    417420    }
    418421
     422    boolean hasNextToken() {
     423        reset();
     424        int ch = peek();
     425
     426        // whitespace
     427        while (ch == 0x20 || ch == 0x09 || ch == 0x0a || ch == 0x0d) {
     428            if (ch == '\r') {
     429                ++lineNo;
     430                ++readBegin;
     431                ch = peek();
     432                if (ch == '\n') {
     433                    lastLineOffset = bufferOffset+readBegin+1;
     434                } else {
     435                    lastLineOffset = bufferOffset+readBegin;
     436                    continue;
     437                }
     438            } else if (ch == '\n') {
     439                ++lineNo;
     440                lastLineOffset = bufferOffset+readBegin+1;
     441            }
     442            ++readBegin;
     443            ch = peek();
     444        }
     445        return ch != -1;
     446    }
     447
     448    private int peek() {
     449        try {
     450            if (readBegin == readEnd) {     // need to fill the buffer
     451                int len = fillBuf();
     452                if (len == -1) {
     453                    return -1;
     454                }
     455                assert len != 0;
     456                readBegin = storeEnd;
     457                readEnd = readBegin+len;
     458            }
     459            return buf[readBegin];
     460        } catch (IOException ioe) {
     461            throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe);
     462        }
     463    }
     464
    419465    // Gives the location of the last char. Used for
    420466    // JsonParsingException.getLocation
     
    499545        // no need to create BigDecimal for common integer values (1-9 digits)
    500546        int storeLen = storeEnd-storeBegin;
    501         if (!fracOrExp && (storeLen <= 9 || (minus && storeLen == 10))) {
     547        if (!fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10))) {
    502548            int num = 0;
    503549            int i = minus ? 1 : 0;
     
    510556        }
    511557    }
     558   
     559    long getLong() {
     560        // no need to create BigDecimal for common integer values (1-18 digits)
     561        int storeLen = storeEnd-storeBegin;
     562        if (!fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19))) {
     563            long num = 0;
     564            int i = minus ? 1 : 0;
     565            for(; i < storeLen; i++) {
     566                num = num * 10 + (buf[storeBegin+i] - '0');
     567            }
     568            return minus ? -num : num;
     569        } else {
     570            return getBigDecimal().longValue();
     571        }
     572    }
    512573
    513574    // returns true for common integer values (1-9 digits).
     
    515576    boolean isDefinitelyInt() {
    516577        int storeLen = storeEnd-storeBegin;
    517         return !fracOrExp && (storeLen <= 9 || (minus && storeLen == 10));
     578        return !fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10));
     579    }
     580   
     581    // returns true for common long values (1-18 digits).
     582    // So there are cases it will return false even though the number is long
     583    boolean isDefinitelyLong() {
     584        int storeLen = storeEnd-storeBegin;
     585        return !fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19));
    518586    }
    519587
Note: See TracChangeset for help on using the changeset viewer.