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