Package org.marketcetera.util.unicode
Enum SignatureCharset
- java.lang.Object
-
- java.lang.Enum<SignatureCharset>
-
- org.marketcetera.util.unicode.SignatureCharset
-
- All Implemented Interfaces:
Serializable,Comparable<SignatureCharset>
public enum SignatureCharset extends Enum<SignatureCharset>
A byte stream signature (Signature) coupled with a charset (UnicodeCharset) that may follow the signature (aka a signature/charset pair). Observe that, in the absence of a signature (Signature.NONE), many different charsets are allowed. Instances of this class enforce signature removal upon decoding and insertion upon charset; there is no attempt made to identify matching signatures, as done bySerialization.- Since:
- 0.6.0
- Version:
- $Id: SignatureCharset.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Enum Constant Summary
Enum Constants Enum Constant Description NONE_UTF16BENONE_UTF16LENONE_UTF32BENONE_UTF32LENONE_UTF8UTF16BE_UTF16BEUTF16LE_UTF16LEUTF32BE_UTF32BEUTF32LE_UTF32LEUTF8_UTF8
-
Field Summary
Fields Modifier and Type Field Description private UnicodeCharsetmCharsetprivate SignaturemSignature
-
Constructor Summary
Constructors Modifier Constructor Description privateSignatureCharset(Signature signature, UnicodeCharset charset)Creates a new signature/charset pair with the given signature and charset.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertSupported()Asserts that the JVM supports the receiver's charset.Stringdecode(byte[] data)Decodes 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.UnicodeCharsetgetCharset()Returns the receiver's charset.SignaturegetSignature()Returns the receiver's signature.booleanisSupported()Checks whether the JVM supports the receiver's charset.static SignatureCharsetvalueOf(String name)Returns the enum constant of this type with the specified name.static SignatureCharset[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
NONE_UTF8
public static final SignatureCharset NONE_UTF8
-
NONE_UTF16BE
public static final SignatureCharset NONE_UTF16BE
-
NONE_UTF16LE
public static final SignatureCharset NONE_UTF16LE
-
NONE_UTF32BE
public static final SignatureCharset NONE_UTF32BE
-
NONE_UTF32LE
public static final SignatureCharset NONE_UTF32LE
-
UTF8_UTF8
public static final SignatureCharset UTF8_UTF8
-
UTF16BE_UTF16BE
public static final SignatureCharset UTF16BE_UTF16BE
-
UTF16LE_UTF16LE
public static final SignatureCharset UTF16LE_UTF16LE
-
UTF32BE_UTF32BE
public static final SignatureCharset UTF32BE_UTF32BE
-
UTF32LE_UTF32LE
public static final SignatureCharset UTF32LE_UTF32LE
-
-
Field Detail
-
mSignature
private final Signature mSignature
-
mCharset
private final UnicodeCharset mCharset
-
-
Constructor Detail
-
SignatureCharset
private SignatureCharset(Signature signature, UnicodeCharset charset)
Creates a new signature/charset pair with the given signature and charset.- Parameters:
signature- The signature.charset- The charset.
-
-
Method Detail
-
values
public static SignatureCharset[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (SignatureCharset c : SignatureCharset.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static SignatureCharset valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getSignature
public Signature getSignature()
Returns the receiver's signature.- Returns:
- The signature.
-
getCharset
public UnicodeCharset getCharset()
Returns the receiver's charset.- Returns:
- The charset.
-
isSupported
public boolean isSupported()
Checks whether the JVM supports the receiver's charset.- Returns:
- True if so.
-
assertSupported
public void assertSupported() throws I18NExceptionAsserts that the JVM supports the receiver's charset.- Throws:
I18NException- Thrown if it does not.
-
decode
public String decode(byte[] data) throws I18NException
Decodes the given byte array using the receiver's charset, and returns the result. The receiver's signature BOM is assumed to be present in the header of the byte array, and is removed (without a check performed to confirm its presence).- Parameters:
data- The byte array, which may be null.- Returns:
- The decoded string; it is null if the given byte array is null.
- Throws:
I18NException- Thrown if the receiver's charset is not a supported JVM charset.
-
encode
public byte[] encode(String data) throws I18NException
Encodes the given string using the receiver's charset, and returns the result. The receiver's signature BOM is always prepended to the header of the returned byte array.- Parameters:
data- The string, which may be null.- Returns:
- The encoded byte array; it is null if the given string is null.
- Throws:
I18NException- Thrown if the receiver's charset is not a supported JVM charset.
-
-