    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      http://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.lang3;
    019
    020import java.nio.charset.Charset;
    021import java.nio.charset.IllegalCharsetNameException;
    022
    023/**
    024 * Character encoding names required of every implementation of the Java platform.
    025 *
    026 * <p>According to <a href="https://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html">JRE character
    027 * encoding names</a>:</p>
    028 *
    029 * <p><cite>Every implementation of the Java platform is required to support the following character encodings.
    030 * Consult the release documentation for your implementation to see if any other encodings are supported.
    031 * </cite></p>
    032 *
    033 * @see <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html">JRE character encoding names</a>
    034 * @since 2.1
    035 * @deprecated Java 7 introduced {@link java.nio.charset.StandardCharsets}, which defines these constants as
    036 * {@link Charset} objects. Use {@link Charset#name()} to get the string values provided in this class.
    037 * This class will be removed in a future release.
    038 */
    039@Deprecated
    040public class CharEncoding {
    041
    042    /**
    043     * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
    044     *
    045     * <p>Every implementation of the Java platform is required to support this character encoding.</p>
    046     */
    047    public static final String ISO_8859_1 = "ISO-8859-1";
    048
    049    /**
    050     * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block
    051     * of the Unicode character set.
    052     *
    053     * <p>Every implementation of the Java platform is required to support this character encoding.</p>
    054     */
    055    public static final String US_ASCII = "US-ASCII";
    056
    057    /**
    058     * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial
    059     * byte-order mark (either order accepted on input, big-endian used on output).
    060     *
    061     * <p>Every implementation of the Java platform is required to support this character encoding.</p>
    062     */
    063    public static final String UTF_16 = "UTF-16";
    064
    065    /**
    066     * Sixteen-bit Unicode Transformation Format, big-endian byte order.
    067     *
    068     * <p>Every implementation of the Java platform is required to support this character encoding.</p>
    069     */
    070    public static final String UTF_16BE = "UTF-16BE";
    071
    072    /**
    073     * Sixteen-bit Unicode Transformation Format, little-endian byte order.
    074     *
    075     * <p>Every implementation of the Java platform is required to support this character encoding.</p>
    076     */
    077    public static final String UTF_16LE = "UTF-16LE";
    078
    079    /**
    080     * Eight-bit Unicode Transformation Format.
    081     *
    082     * <p>Every implementation of the Java platform is required to support this character encoding.</p>
    083     */
    084    public static final String UTF_8 = "UTF-8";
    085
    086    /**
    087     * Returns whether the named charset is supported.
    088     *
    089     * <p>This is similar to <a
    090     * href="https://docs.oracle.com/javase/8/docs/api/java/nio/charset/Charset.html#isSupported%28java.lang.String%29">
    091     * java.nio.charset.Charset.isSupported(String)</a> but handles more formats</p>
    092     *
    093     * @param name  the name of the requested charset; may be either a canonical name or an alias, null returns false
    094     * @return {@code true} if the charset is available in the current Java virtual machine
    095     * @deprecated Please use {@link Charset#isSupported(String)} instead, although be aware that {@code null}
    096     * values are not accepted by that method and an {@link IllegalCharsetNameException} may be thrown.
    097     */
    098    @Deprecated
    099    public static boolean isSupported(final String name) {
    100        if (name == null) {
    101            return false;
    102        }
    103        try {
    104            return Charset.isSupported(name);
    105        } catch (final IllegalCharsetNameException ex) {
    106            return false;
    107        }
    108    }
    109
    110}