Changeset 13231 in josm for trunk/src/org/glassfish/json/UnicodeDetectingInputStream.java
- Timestamp:
- 2017-12-23T02:40:43+01:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/glassfish/json/UnicodeDetectingInputStream.java
r6756 r13231 2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 3 * 4 * Copyright (c) 2012-201 3Oracle and/or its affiliates. All rights reserved.4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 5 * 6 6 * The contents of this file are subject to the terms of either the GNU … … 9 9 * may not use this file except in compliance with the License. You can 10 10 * obtain a copy of the License at 11 * https:// glassfish.dev.java.net/public/CDDL+GPL_1_1.html12 * or packager/legal/LICENSE.txt. See the License for the specific11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 * or LICENSE.txt. See the License for the specific 13 13 * language governing permissions and limitations under the License. 14 14 * 15 15 * 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. 17 17 * 18 18 * GPL Classpath Exception: … … 46 46 import java.io.InputStream; 47 47 import java.nio.charset.Charset; 48 import java.nio.charset.StandardCharsets; 48 49 49 50 /** … … 54 55 */ 55 56 class 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 59 58 private static final Charset UTF_32LE = Charset.forName("UTF-32LE"); 60 59 private static final Charset UTF_32BE = Charset.forName("UTF-32BE"); … … 122 121 buf[3] = (byte)b4; 123 122 } 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); 125 124 } 126 125 } … … 129 128 fillBuf(); 130 129 if (bufLen < 2) { 131 throw new JsonException( "Cannot auto-detect encoding, not enough chars");130 throw new JsonException(JsonMessages.PARSER_INPUT_ENC_DETECT_FAILED()); 132 131 } else if (bufLen == 4) { 133 132 // Use BOM to detect encoding … … 140 139 } else if (buf[0] == FE && buf[1] == FF) { 141 140 curIndex = 2; 142 return UTF_16BE; 141 return StandardCharsets.UTF_16BE; 143 142 } else if (buf[0] == FF && buf[1] == FE) { 144 143 curIndex = 2; 145 return UTF_16LE; 144 return StandardCharsets.UTF_16LE; 146 145 } else if (buf[0] == EF && buf[1] == BB && buf[2] == BF) { 147 146 curIndex = 3; 148 return UTF_8; 147 return StandardCharsets.UTF_8; 149 148 } 150 149 // No BOM, just use JSON RFC's encoding algo to auto-detect … … 152 151 return UTF_32BE; 153 152 } else if (buf[0] == NUL && buf[2] == NUL) { 154 return UTF_16BE; 153 return StandardCharsets.UTF_16BE; 155 154 } else if (buf[1] == NUL && buf[2] == NUL && buf[3] == NUL) { 156 155 return UTF_32LE; 157 156 } else if (buf[1] == NUL && buf[3] == NUL) { 158 return UTF_16LE; 157 return StandardCharsets.UTF_16LE; 159 158 } 160 159 } 161 return UTF_8; 160 return StandardCharsets.UTF_8; 162 161 } 163 162
Note:
See TracChangeset
for help on using the changeset viewer.
