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 * http://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.lang;
19
20 import java.io.UnsupportedEncodingException;
21
22 /**
23 * <p>
24 * Character encoding names required of every implementation of the Java platform.
25 * </p>
26 *
27 * <p>
28 * According to <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
29 * encoding names</a>:
30 * <p>
31 * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
32 * release documentation for your implementation to see if any other encodings are supported.</cite>
33 * </p>
34 * </p>
35 *
36 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character encoding
37 * names</a>
38 * @author Apache Software Foundation
39 * @since 2.1
40 * @version $Id: CharEncoding.java 437554 2006-08-28 06:21:41Z bayard $
41 */
42 public class CharEncoding {
43
44 /**
45 * <p>
46 * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
47 * </p>
48 * <p>
49 * Every implementation of the Java platform is required to support this character encoding.
50 * </p>
51 *
52 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
53 * encoding names</a>
54 */
55 public static final String ISO_8859_1 = "ISO-8859-1";
56
57 /**
58 * <p>
59 * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
60 * </p>
61 * <p>
62 * Every implementation of the Java platform is required to support this character encoding.
63 * </p>
64 *
65 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
66 * encoding names</a>
67 */
68 public static final String US_ASCII = "US-ASCII";
69
70 /**
71 * <p>
72 * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
73 * order accepted on input, big-endian used on output).
74 * </p>
75 * <p>
76 * Every implementation of the Java platform is required to support this character encoding.
77 * </p>
78 *
79 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
80 * encoding names</a>
81 */
82 public static final String UTF_16 = "UTF-16";
83
84 /**
85 * <p>
86 * Sixteen-bit Unicode Transformation Format, big-endian byte order.
87 * </p>
88 * <p>
89 * Every implementation of the Java platform is required to support this character encoding.
90 * </p>
91 *
92 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
93 * encoding names</a>
94 */
95 public static final String UTF_16BE = "UTF-16BE";
96
97 /**
98 * <p>
99 * Sixteen-bit Unicode Transformation Format, little-endian byte order.
100 * </p>
101 * <p>
102 * Every implementation of the Java platform is required to support this character encoding.
103 * </p>
104 *
105 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
106 * encoding names</a>
107 */
108 public static final String UTF_16LE = "UTF-16LE";
109
110 /**
111 * <p>
112 * Eight-bit Unicode Transformation Format.
113 * </p>
114 * <p>
115 * Every implementation of the Java platform is required to support this character encoding.
116 * </p>
117 *
118 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
119 * encoding names</a>
120 */
121 public static final String UTF_8 = "UTF-8";
122
123 /**
124 * <p>
125 * Returns whether the named charset is supported.
126 * </p>
127 * <p>
128 * This is similar to <a
129 * href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html#isSupported(java.lang.String)">
130 * java.nio.charset.Charset.isSupported(String)</a>
131 * </p>
132 *
133 * @param name
134 * the name of the requested charset; may be either a canonical name or an alias
135 * @return <code>true</code> if, and only if, support for the named charset is available in the current Java
136 * virtual machine
137 *
138 * @see <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
139 * encoding names</a>
140 */
141 public static boolean isSupported(String name) {
142 if (name == null) {
143 return false;
144 }
145 try {
146 new String(ArrayUtils.EMPTY_BYTE_ARRAY, name);
147 } catch (UnsupportedEncodingException e) {
148 return false;
149 }
150 return true;
151 }
152
153 }