    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 *      https://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.codec;
    019
    020import java.nio.charset.Charset;
    021import java.nio.charset.StandardCharsets;
    022
    023/**
    024 * Character encoding names required of every implementation of the Java platform.
    025 *
    026 * From the Java documentation for {@link Charset}:
    027 * <p>
    028 * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
    029 * release documentation for your implementation to see if any other encodings are supported. Consult the release
    030 * documentation for your implementation to see if any other encodings are supported.</cite>
    031 * </p>
    032 *
    033 * <ul>
    034 * <li>{@code US-ASCII}<p>
    035 * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</p></li>
    036 * <li>{@code ISO-8859-1}<p>
    037 * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</p></li>
    038 * <li>{@code UTF-8}<p>
    039 * Eight-bit Unicode Transformation Format.</p></li>
    040 * <li>{@code UTF-16BE}<p>
    041 * Sixteen-bit Unicode Transformation Format, big-endian byte order.</p></li>
    042 * <li>{@code UTF-16LE}<p>
    043 * Sixteen-bit Unicode Transformation Format, little-endian byte order.</p></li>
    044 * <li>{@code UTF-16}<p>
    045 * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
    046 * accepted on input, big-endian used on output.)</p></li>
    047 * </ul>
    048 *
    049 * This perhaps would best belong in the [lang] project. Even if a similar interface is defined in [lang], it is not
    050 * foreseen that [codec] would be made to depend on [lang].
    051 *
    052 * <p>
    053 * This class is immutable and thread-safe.
    054 * </p>
    055 *
    056 * @see Charset
    057 * @since 1.4
    058 */
    059public class CharEncoding {
    060
    061    /**
    062     * CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
    063     * <p>
    064     * Every implementation of the Java platform is required to support this character encoding.
    065     * </p>
    066     *
    067     * @see Charset
    068     */
    069    public static final String ISO_8859_1 = StandardCharsets.ISO_8859_1.name();
    070
    071    /**
    072     * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
    073     * <p>
    074     * Every implementation of the Java platform is required to support this character encoding.
    075     * </p>
    076     *
    077     * @see Charset
    078     */
    079    public static final String US_ASCII = StandardCharsets.US_ASCII.name();
    080
    081    /**
    082     * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
    083     * (either order accepted on input, big-endian used on output)
    084     * <p>
    085     * Every implementation of the Java platform is required to support this character encoding.
    086     * </p>
    087     *
    088     * @see Charset
    089     */
    090    public static final String UTF_16 = StandardCharsets.UTF_16.name();
    091
    092    /**
    093     * Sixteen-bit Unicode Transformation Format, big-endian byte order.
    094     * <p>
    095     * Every implementation of the Java platform is required to support this character encoding.
    096     * </p>
    097     *
    098     * @see Charset
    099     */
    100    public static final String UTF_16BE = StandardCharsets.UTF_16BE.name();
    101
    102    /**
    103     * Sixteen-bit Unicode Transformation Format, little-endian byte order.
    104     * <p>
    105     * Every implementation of the Java platform is required to support this character encoding.
    106     * </p>
    107     *
    108     * @see Charset
    109     */
    110    public static final String UTF_16LE = StandardCharsets.UTF_16LE.name();
    111
    112    /**
    113     * Eight-bit Unicode Transformation Format.
    114     * <p>
    115     * Every implementation of the Java platform is required to support this character encoding.
    116     * </p>
    117     *
    118     * @see Charset
    119     */
    120    public static final String UTF_8 = StandardCharsets.UTF_8.name();
    121
    122    /**
    123     * TODO Make private in 2.0.
    124     *
    125     * @deprecated TODO Make private in 2.0.
    126     */
    127    @Deprecated
    128    public CharEncoding() {
    129        // empty
    130    }
    131
    132}