Converters.java revision 3261
286N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. 286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/A * This code is free software; you can redistribute it and/or modify it 286N/A * under the terms of the GNU General Public License version 2 only, as 286N/A * published by the Free Software Foundation. Oracle designates this 286N/A * particular file as subject to the "Classpath" exception as provided 286N/A * by Oracle in the LICENSE file that accompanied this code. 286N/A * This code is distributed in the hope that it will be useful, but WITHOUT 286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/A * version 2 for more details (a copy is included in the LICENSE file that 286N/A * accompanied this code). 286N/A * You should have received a copy of the GNU General Public License version 286N/A * 2 along with this work; if not, write to the Free Software Foundation, 286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A * or visit www.oracle.com if you need additional information or have any 286N/A * Package-private utility class that caches the default converter classes and 286N/A * provides other logic common to both the ByteToCharConverter and 286N/A * CharToByteConverter classes. 286N/A * @author Mark Reinhold 286N/A * @deprecated Replaced by {@link java.nio.charset}. THIS API WILL BE 286N/A /* Lock for all static fields in this class */ 286N/A /* Cached values of system properties */ 286N/A /* Converter type constants and names */ 286N/A // -- Converter class cache -- 286N/A /* For the default charset, whatever it turns out to be */ 286N/A /* Cached converter classes, CACHE_SIZE per converter type. Each cache 286N/A * entry is a soft reference to a two-object array; the first element of 286N/A * the array is the converter class, the second is an object (typically a 286N/A * string) representing the encoding name that was used to request the 286N/A * ((Object[])classCache[CHAR_TO_BYTE][i].get())[0] 286N/A * will be a CharToByteConverter and 286N/A * ((Object[])classCache[CHAR_TO_BYTE][i].get())[1] 286N/A * will be the string encoding name used to request it, assuming that cache 286N/A * Ordinarily we'd do this with a private static utility class, but since 286N/A * this code can be involved in the startup sequence it's important to keep 286N/A for (
int j = i; j >
0; j--)
286N/A /* Used to avoid doing expensive charset lookups for charsets that are not 286N/A * yet directly supported by NIO. 286N/A /** Get the name of the converter package */ 286N/A /* Property is set, so take it as the true converter package */ 286N/A /* Fall back to sun.io */ 286N/A // This method should only be called during VM initialization. 286N/A * Get the class that implements the given type of converter for the named 286N/A * encoding, or throw an UnsupportedEncodingException if no such class can 286N/A /* "ISO8859_1" is the canonical name for the ISO-Latin-1 encoding. 286N/A Native code in the JDK commonly uses the alias "8859_1" instead of 286N/A "ISO8859_1". We hardwire this alias here in order to avoid loading 286N/A the full alias table just for this case. */ 286N/A * On Solaris with nl_langinfo() called in GetJavaProperties(): 286N/A * locale undefined -> NULL -> hardcoded default 286N/A * "C" locale -> "" -> hardcoded default (on 2.6) 286N/A * "C" locale -> "646" (on 2.7) 286N/A * "en_US" locale -> "ISO8859-1" 286N/A * "en_GB" locale -> "ISO8859-1" (on 2.7) 286N/A * "en_UK" locale -> "ISO8859-1" (on 2.6) 286N/A * Instantiate the given converter class, or throw an 286N/A * UnsupportedEncodingException if it cannot be instantiated 286N/A * Create a converter object that implements the given type of converter 286N/A * for the given encoding, or throw an UnsupportedEncodingException if no 286N/A * appropriate converter class can be found and instantiated 286N/A * Find the class that implements the given type of converter for the 286N/A * default encoding. If the default encoding cannot be determined or is 286N/A * not yet defined, return a class that implements the fallback default 286N/A * encoding, which is just ISO 8859-1. 286N/A /* First check the class cache */ 286N/A /* Determine the encoding name */ 286N/A /* file.encoding has been set, so cache the converter class */ 286N/A /* file.encoding has not been set, so use a default encoding which 286N/A /* We have an encoding name; try to find its class */ 286N/A /* Can't find the default class, so fall back to ISO 8859-1 */ 286N/A * Create a converter object that implements the given type of converter 286N/A * for the default encoding, falling back to ISO 8859-1 if the default 286N/A * encoding cannot be determined.