CharEncoding.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.apache.commons.codec;

  18. import java.nio.charset.Charset;
  19. import java.nio.charset.StandardCharsets;

  20. /**
  21.  * Character encoding names required of every implementation of the Java platform.
  22.  *
  23.  * From the Java documentation for {@link Charset}:
  24.  * <p>
  25.  * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
  26.  * release documentation for your implementation to see if any other encodings are supported. Consult the release
  27.  * documentation for your implementation to see if any other encodings are supported.</cite>
  28.  * </p>
  29.  *
  30.  * <ul>
  31.  * <li>{@code US-ASCII}<p>
  32.  * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</p></li>
  33.  * <li>{@code ISO-8859-1}<p>
  34.  * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</p></li>
  35.  * <li>{@code UTF-8}<p>
  36.  * Eight-bit Unicode Transformation Format.</p></li>
  37.  * <li>{@code UTF-16BE}<p>
  38.  * Sixteen-bit Unicode Transformation Format, big-endian byte order.</p></li>
  39.  * <li>{@code UTF-16LE}<p>
  40.  * Sixteen-bit Unicode Transformation Format, little-endian byte order.</p></li>
  41.  * <li>{@code UTF-16}<p>
  42.  * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
  43.  * accepted on input, big-endian used on output.)</p></li>
  44.  * </ul>
  45.  *
  46.  * This perhaps would best belong in the [lang] project. Even if a similar interface is defined in [lang], it is not
  47.  * foreseen that [codec] would be made to depend on [lang].
  48.  *
  49.  * <p>
  50.  * This class is immutable and thread-safe.
  51.  * </p>
  52.  *
  53.  * @see Charset
  54.  * @since 1.4
  55.  */
  56. public class CharEncoding {

  57.     /**
  58.      * CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
  59.      * <p>
  60.      * Every implementation of the Java platform is required to support this character encoding.
  61.      * </p>
  62.      *
  63.      * @see Charset
  64.      */
  65.     public static final String ISO_8859_1 = StandardCharsets.ISO_8859_1.name();

  66.     /**
  67.      * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
  68.      * <p>
  69.      * Every implementation of the Java platform is required to support this character encoding.
  70.      * </p>
  71.      *
  72.      * @see Charset
  73.      */
  74.     public static final String US_ASCII = StandardCharsets.US_ASCII.name();

  75.     /**
  76.      * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
  77.      * (either order accepted on input, big-endian used on output)
  78.      * <p>
  79.      * Every implementation of the Java platform is required to support this character encoding.
  80.      * </p>
  81.      *
  82.      * @see Charset
  83.      */
  84.     public static final String UTF_16 = StandardCharsets.UTF_16.name();

  85.     /**
  86.      * Sixteen-bit Unicode Transformation Format, big-endian byte order.
  87.      * <p>
  88.      * Every implementation of the Java platform is required to support this character encoding.
  89.      * </p>
  90.      *
  91.      * @see Charset
  92.      */
  93.     public static final String UTF_16BE = StandardCharsets.UTF_16BE.name();

  94.     /**
  95.      * Sixteen-bit Unicode Transformation Format, little-endian byte order.
  96.      * <p>
  97.      * Every implementation of the Java platform is required to support this character encoding.
  98.      * </p>
  99.      *
  100.      * @see Charset
  101.      */
  102.     public static final String UTF_16LE = StandardCharsets.UTF_16LE.name();

  103.     /**
  104.      * Eight-bit Unicode Transformation Format.
  105.      * <p>
  106.      * Every implementation of the Java platform is required to support this character encoding.
  107.      * </p>
  108.      *
  109.      * @see Charset
  110.      */
  111.     public static final String UTF_8 = StandardCharsets.UTF_8.name();

  112.     /**
  113.      * TODO Make private in 2.0.
  114.      *
  115.      * @deprecated TODO Make private in 2.0.
  116.      */
  117.     @Deprecated
  118.     public CharEncoding() {
  119.         // empty
  120.     }

  121. }