org.marketcetera.util.unicode
Enum SignatureCharset

java.lang.Object
  extended by java.lang.Enum<SignatureCharset>
      extended by 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 by Serialization.

Since:
0.6.0
Version:
$Id: SignatureCharset.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Enum Constant Summary
NONE_UTF16BE
           
NONE_UTF16LE
           
NONE_UTF32BE
           
NONE_UTF32LE
           
NONE_UTF8
           
UTF16BE_UTF16BE
           
UTF16LE_UTF16LE
           
UTF32BE_UTF32BE
           
UTF32LE_UTF32LE
           
UTF8_UTF8
           
 
Method Summary
 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.
 byte[] encode(String data)
          Encodes the given string using the receiver's charset, and returns the result.
 UnicodeCharset getCharset()
          Returns the receiver's charset.
 Signature getSignature()
          Returns the receiver's signature.
 boolean isSupported()
          Checks whether the JVM supports the receiver's charset.
static SignatureCharset valueOf(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.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

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
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 name
NullPointerException - 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 I18NException
Asserts 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.


Copyright © 2012. All Rights Reserved.