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
18 package org.apache.commons.codec;
19
20 import java.nio.charset.Charset;
21 import java.nio.charset.StandardCharsets;
22
23 /**
24 * Character encoding names required of every implementation of the Java platform.
25 *
26 * From the Java documentation for {@link Charset}:
27 * <p>
28 * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
29 * release documentation for your implementation to see if any other encodings are supported. Consult the release
30 * documentation for your implementation to see if any other encodings are supported.</cite>
31 * </p>
32 *
33 * <ul>
34 * <li>{@code US-ASCII}
35 * <p>
36 * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.
37 * </p>
38 * </li>
39 * <li>{@code ISO-8859-1}
40 * <p>
41 * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
42 * </p>
43 * </li>
44 * <li>{@code UTF-8}
45 * <p>
46 * Eight-bit Unicode Transformation Format.
47 * </p>
48 * </li>
49 * <li>{@code UTF-16BE}
50 * <p>
51 * Sixteen-bit Unicode Transformation Format, big-endian byte order.
52 * </p>
53 * </li>
54 * <li>{@code UTF-16LE}
55 * <p>
56 * Sixteen-bit Unicode Transformation Format, little-endian byte order.
57 * </p>
58 * </li>
59 * <li>{@code UTF-16}
60 * <p>
61 * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
62 * accepted on input, big-endian used on output.)
63 * </p>
64 * </li>
65 * </ul>
66 *
67 * This perhaps would best belong in the [lang] project. Even if a similar interface is defined in [lang], it is not
68 * foreseen that [codec] would be made to depend on [lang].
69 *
70 * <p>
71 * This class is immutable and thread-safe.
72 * </p>
73 *
74 * @see Charset
75 * @since 1.4
76 */
77 public class CharEncoding {
78
79 /**
80 * CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.
81 * <p>
82 * Every implementation of the Java platform is required to support this character encoding.
83 * </p>
84 *
85 * @see Charset
86 */
87 public static final String ISO_8859_1 = StandardCharsets.ISO_8859_1.name();
88
89 /**
90 * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
91 * <p>
92 * Every implementation of the Java platform is required to support this character encoding.
93 * </p>
94 *
95 * @see Charset
96 */
97 public static final String US_ASCII = StandardCharsets.US_ASCII.name();
98
99 /**
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 }