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