public enum UnicodeCharset extends Enum<UnicodeCharset>
Charset for the Unicode charsets.
Java inserts a BOM when a string is encoded into a byte array with the generic (neither LE or BE) UTF-16 charset. Java does not do that for the generic UTF-32, or UTF-8. As a result, the generic UTF-16 and UTF-32 are avoided by other classes in this package, opting instead for the more consistent LE/BE variants that never insert a BOM (and, upon decoding, ignore one if present).
Since Java 5, strings are internally stored in UTF-16, not UCS-2, which means that they can represent code points above 0xFFFF.
UTF-32 encodings may not be supported on all platforms.
| Enum Constant and Description |
|---|
UTF16 |
UTF16BE |
UTF16LE |
UTF32 |
UTF32BE |
UTF32LE |
UTF8 |
| Modifier and Type | Method and Description |
|---|---|
void |
assertSupported()
Asserts that the JVM supports the receiver's charset.
|
String |
decode(byte[] data)
Decodes the given byte array using the receiver's charset, and
returns the result.
|
String |
decode(byte[] data,
int offset,
int length)
Decodes the given portion of the given byte array using the
receiver's charset, and returns the result.
|
byte[] |
encode(String data)
Encodes the given string using the receiver's charset, and
returns the result.
|
Charset |
getCharset()
Returns the receiver's wrapped Java charset.
|
String |
getName()
Returns the receiver's name.
|
boolean |
isSupported()
Checks whether the JVM supports the receiver's charset.
|
static UnicodeCharset |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static UnicodeCharset[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final UnicodeCharset UTF8
public static final UnicodeCharset UTF16BE
public static final UnicodeCharset UTF16LE
public static final UnicodeCharset UTF16
public static final UnicodeCharset UTF32BE
public static final UnicodeCharset UTF32LE
public static final UnicodeCharset UTF32
public static UnicodeCharset[] values()
for (UnicodeCharset c : UnicodeCharset.values()) System.out.println(c);
public static UnicodeCharset valueOf(String name)
name - the name of the enum constant to be returned.IllegalArgumentException - if this enum type has no constant
with the specified nameNullPointerException - if the argument is nullpublic String getName()
public Charset getCharset()
public boolean isSupported()
public void assertSupported()
throws I18NException
I18NException - Thrown if it does not.public String decode(byte[] data, int offset, int length) throws I18NException
data - The byte array, which may be null.offset - The starting point for decoding.length - The number of bytes to decode.I18NException - Thrown if the receiver is not a supported
JVM charset.public String decode(byte[] data) throws I18NException
data - The byte array, which may be null.I18NException - Thrown if the receiver is not a supported
JVM charset.public byte[] encode(String data) throws I18NException
data - The string, which may be null.I18NException - Thrown if the receiver is not a supported
JVM charset.Copyright © 2015. All Rights Reserved.