Skip to content

Commit 453c56c

Browse files
committed
[CODEC-136] Use Charset objects when possible, create Charsets for required character encodings.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/codec/trunk@1306366 13f79535-47bb-0310-9956-ffa450edef68
1 parent 65d05e0 commit 453c56c

4 files changed

Lines changed: 321 additions & 75 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ limitations under the License.
196196
</dependency>
197197
</dependencies>
198198
<properties>
199-
<maven.compile.source>1.5</maven.compile.source>
200-
<maven.compile.target>1.5</maven.compile.target>
199+
<maven.compile.source>1.6</maven.compile.source>
200+
<maven.compile.target>1.6</maven.compile.target>
201201
<commons.componentid>codec</commons.componentid>
202202
<commons.release.version>1.7</commons.release.version>
203203
<!-- The RC version used in the staging repository URL. -->
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
package org.apache.commons.codec;
18+
19+
import java.nio.charset.Charset;
20+
21+
/**
22+
* Charsets required of every implementation of the Java platform.
23+
*
24+
* From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard
25+
* charsets</a>:
26+
* <p>
27+
* <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
28+
* release documentation for your implementation to see if any other encodings are supported. Consult the release
29+
* documentation for your implementation to see if any other encodings are supported. </cite>
30+
* </p>
31+
*
32+
* <ul>
33+
* <li><code>US-ASCII</code><br/>
34+
* Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</li>
35+
* <li><code>ISO-8859-1</code><br/>
36+
* ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</li>
37+
* <li><code>UTF-8</code><br/>
38+
* Eight-bit Unicode Transformation Format.</li>
39+
* <li><code>UTF-16BE</code><br/>
40+
* Sixteen-bit Unicode Transformation Format, big-endian byte order.</li>
41+
* <li><code>UTF-16LE</code><br/>
42+
* Sixteen-bit Unicode Transformation Format, little-endian byte order.</li>
43+
* <li><code>UTF-16</code><br/>
44+
* Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
45+
* accepted on input, big-endian used on output.)</li>
46+
* </ul>
47+
*
48+
* This perhaps would best belong in the Commons Lang project. Even if a similar class is defined in Commons Lang, it is
49+
* not foreseen that Commons Codec would be made to depend on Commons Lang.
50+
*
51+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
52+
* @author Apache Software Foundation
53+
* @since 1.7
54+
* @version $Id: CharEncoding.java 1173287 2011-09-20 18:16:19Z ggregory $
55+
*/
56+
public class Charsets {
57+
//
58+
// This class should only contain Charset instances for required encodings. This guarantees that it will load correctly and
59+
// without delay on all Java platforms.
60+
//
61+
/**
62+
* CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1. </p>
63+
* <p>
64+
* Every implementation of the Java platform is required to support this character encoding.
65+
* </p>
66+
*
67+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
68+
*/
69+
public static final Charset ISO_8859_1 = Charset.forName(CharEncoding.ISO_8859_1);
70+
71+
/**
72+
* <p>
73+
* Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
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://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
80+
*/
81+
public static final Charset US_ASCII = Charset.forName(CharEncoding.US_ASCII);
82+
83+
/**
84+
* <p>
85+
* Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
86+
* (either order accepted on input, big-endian used on output)
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://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
93+
*/
94+
public static final Charset UTF_16 = Charset.forName(CharEncoding.UTF_16);
95+
96+
/**
97+
* <p>
98+
* Sixteen-bit Unicode Transformation Format, big-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://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
105+
*/
106+
public static final Charset UTF_16BE = Charset.forName(CharEncoding.UTF_16BE);
107+
108+
/**
109+
* <p>
110+
* Sixteen-bit Unicode Transformation Format, little-endian byte order.
111+
* </p>
112+
* <p>
113+
* Every implementation of the Java platform is required to support this character encoding.
114+
* </p>
115+
*
116+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
117+
*/
118+
public static final Charset UTF_16LE = Charset.forName(CharEncoding.UTF_16LE);
119+
120+
/**
121+
* <p>
122+
* Eight-bit Unicode Transformation Format.
123+
* </p>
124+
* <p>
125+
* Every implementation of the Java platform is required to support this character encoding.
126+
* </p>
127+
*
128+
* @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
129+
*/
130+
public static final Charset UTF_8 = Charset.forName(CharEncoding.UTF_8);
131+
}

0 commit comments

Comments
 (0)