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/UnicodeDetectingInputStream.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:
     
    4646import java.io.InputStream;
    4747import java.nio.charset.Charset;
     48import java.nio.charset.StandardCharsets;
    4849
    4950/**
     
    5455 */
    5556class UnicodeDetectingInputStream extends FilterInputStream {
    56     private static final Charset UTF_8 = Charset.forName("UTF-8");
    57     private static final Charset UTF_16BE = Charset.forName("UTF-16BE");
    58     private static final Charset UTF_16LE = Charset.forName("UTF-16LE");
     57
    5958    private static final Charset UTF_32LE = Charset.forName("UTF-32LE");
    6059    private static final Charset UTF_32BE = Charset.forName("UTF-32BE");
     
    122121            buf[3] = (byte)b4;
    123122        } catch (IOException ioe) {
    124             throw new JsonException("I/O error while auto-detecting the encoding of stream", ioe);
     123            throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_IOERR(), ioe);
    125124        }
    126125    }
     
    129128        fillBuf();
    130129        if (bufLen < 2) {
    131             throw new JsonException("Cannot auto-detect encoding, not enough chars");
     130            throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_FAILED());
    132131        } else if (bufLen == 4) {
    133132            // Use BOM to detect encoding
     
    140139            } else if (buf[0] == FE && buf[1] == FF) {
    141140                curIndex = 2;
    142                 return UTF_16BE;
     141                return StandardCharsets.UTF_16BE;
    143142            } else if (buf[0] == FF && buf[1] == FE) {
    144143                curIndex = 2;
    145                 return UTF_16LE;
     144                return StandardCharsets.UTF_16LE;
    146145            } else if (buf[0] == EF && buf[1] == BB && buf[2] == BF) {
    147146                curIndex = 3;
    148                 return UTF_8;
     147                return StandardCharsets.UTF_8;
    149148            }
    150149            // No BOM, just use JSON RFC's encoding algo to auto-detect
     
    152151                return UTF_32BE;
    153152            } else if (buf[0] == NUL && buf[2] == NUL) {
    154                 return UTF_16BE;
     153                return StandardCharsets.UTF_16BE;
    155154            } else if (buf[1] == NUL && buf[2] == NUL && buf[3] == NUL) {
    156155                return UTF_32LE;
    157156            } else if (buf[1] == NUL && buf[3] == NUL) {
    158                 return UTF_16LE;
     157                return StandardCharsets.UTF_16LE;
    159158            }
    160159        }
    161         return UTF_8;
     160        return StandardCharsets.UTF_8;
    162161    }
    163162
Note: See TracChangeset for help on using the changeset viewer.