KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > lang > CharEncoding


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

16
17 package org.apache.commons.lang;
18
19 import java.io.UnsupportedEncodingException JavaDoc;
20
21 /**
22  * <p>
23  * Character encoding names required of every implementation of the Java platform.
24  * </p>
25  *
26  * <p>
27  * According to <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
28  * encoding names</a>:
29  * <p>
30  * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
31  * release documentation for your implementation to see if any other encodings are supported.</cite>
32  * </p>
33  * </p>
34  *
35  * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character encoding
36  * names</a>
37  * @author Apache Software Foundation
38  * @since 2.1
39  * @version $Id: CharEncoding.java 165657 2005-05-02 18:31:49Z ggregory $
40  */

41 public class CharEncoding {
42
43     /**
44      * <p>
45      * ISO Latin Alphabet #1, also known as ISO-LATIN-1.
46      * </p>
47      * <p>
48      * Every implementation of the Java platform is required to support this character encoding.
49      * </p>
50      *
51      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
52      * encoding names</a>
53      */

54     public static final String JavaDoc ISO_8859_1 = "ISO-8859-1";
55
56     /**
57      * <p>
58      * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
59      * </p>
60      * <p>
61      * Every implementation of the Java platform is required to support this character encoding.
62      * </p>
63      *
64      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
65      * encoding names</a>
66      */

67     public static final String JavaDoc US_ASCII = "US-ASCII";
68
69     /**
70      * <p>
71      * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either
72      * order accepted on input, big-endian used on output).
73      * </p>
74      * <p>
75      * Every implementation of the Java platform is required to support this character encoding.
76      * </p>
77      *
78      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
79      * encoding names</a>
80      */

81     public static final String JavaDoc UTF_16 = "UTF-16";
82
83     /**
84      * <p>
85      * Sixteen-bit Unicode Transformation Format, big-endian byte order.
86      * </p>
87      * <p>
88      * Every implementation of the Java platform is required to support this character encoding.
89      * </p>
90      *
91      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
92      * encoding names</a>
93      */

94     public static final String JavaDoc UTF_16BE = "UTF-16BE";
95
96     /**
97      * <p>
98      * Sixteen-bit Unicode Transformation Format, little-endian byte order.
99      * </p>
100      * <p>
101      * Every implementation of the Java platform is required to support this character encoding.
102      * </p>
103      *
104      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
105      * encoding names</a>
106      */

107     public static final String JavaDoc UTF_16LE = "UTF-16LE";
108
109     /**
110      * <p>
111      * Eight-bit Unicode Transformation Format.
112      * </p>
113      * <p>
114      * Every implementation of the Java platform is required to support this character encoding.
115      * </p>
116      *
117      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
118      * encoding names</a>
119      */

120     public static final String JavaDoc UTF_8 = "UTF-8";
121
122     /**
123      * <p>
124      * Returns whether the named charset is supported.
125      * </p>
126      * <p>
127      * This is similar to <a
128      * HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html#isSupported(java.lang.String)">
129      * java.nio.charset.Charset.isSupported(String)</a>
130      * </p>
131      *
132      * @param name
133      * the name of the requested charset; may be either a canonical name or an alias
134      * @return <code>true</code> if, and only if, support for the named charset is available in the current Java
135      * virtual machine
136      *
137      * @see <a HREF="http://java.sun.com/j2se/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
138      * encoding names</a>
139      */

140     public static boolean isSupported(String JavaDoc name) {
141         if (name == null) {
142             return false;
143         }
144         try {
145             new String JavaDoc(ArrayUtils.EMPTY_BYTE_ARRAY, name);
146         } catch (UnsupportedEncodingException JavaDoc e) {
147             return false;
148         }
149         return true;
150     }
151
152 }
153
Popular Tags