Package org.marketcetera.util.unicode
Enum Serialization
- java.lang.Object
-
- java.lang.Enum<Serialization>
-
- org.marketcetera.util.unicode.Serialization
-
- All Implemented Interfaces:
Serializable,Comparable<Serialization>
public enum Serialization extends Enum<Serialization>
A list of signature/charset pairs. This list defines a sequence of signatures that we attempt to match (in order) against a byte array header, and the associated charset we use if a match is found. Most instances of this class correspond to the entries in Table 2 of this reference document.- Since:
- 0.6.0
- Version:
- $Id: Serialization.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Enum Constant Summary
Enum Constants Enum Constant Description UTF16UTF16BEUTF16BE_REQUTF16LEUTF16LE_REQUTF32UTF32BEUTF32BE_REQUTF32LEUTF32LE_REQUTF8UTF8N
-
Field Summary
Fields Modifier and Type Field Description private SignatureCharset[]mSignatureCharsets
-
Constructor Summary
Constructors Modifier Constructor Description privateSerialization(SignatureCharset signatureCharset)Creates a new serialization with only the given signature/charset pair.privateSerialization(SignatureCharset[] signatureCharsets)Creates a new serialization with the given signature/charset pairs.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Stringdecode(Serialization[] candidates, byte[] data)Decodes the given byte array using the charset paired to a signature (among the pairs of the given serializations) that matches the array header, and returns the result.static SignatureCharsetgetPrefixMatch(Serialization[] candidates, byte[] data)Checks whether any of the signatures among the pairs of the given serializations matches the header of the given byte array, and returns the matching signature/charset pair.SignatureCharset[]getSignatureCharsets()Returns the receiver's signature/charset pairs.static SerializationvalueOf(String name)Returns the enum constant of this type with the specified name.static Serialization[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
UTF8
public static final Serialization UTF8
-
UTF8N
public static final Serialization UTF8N
-
UTF16
public static final Serialization UTF16
-
UTF16BE
public static final Serialization UTF16BE
-
UTF16LE
public static final Serialization UTF16LE
-
UTF32
public static final Serialization UTF32
-
UTF32BE
public static final Serialization UTF32BE
-
UTF32LE
public static final Serialization UTF32LE
-
UTF16BE_REQ
public static final Serialization UTF16BE_REQ
-
UTF16LE_REQ
public static final Serialization UTF16LE_REQ
-
UTF32BE_REQ
public static final Serialization UTF32BE_REQ
-
UTF32LE_REQ
public static final Serialization UTF32LE_REQ
-
-
Field Detail
-
mSignatureCharsets
private final SignatureCharset[] mSignatureCharsets
-
-
Constructor Detail
-
Serialization
private Serialization(SignatureCharset signatureCharset)
Creates a new serialization with only the given signature/charset pair.- Parameters:
signatureCharset- The pair.
-
Serialization
private Serialization(SignatureCharset[] signatureCharsets)
Creates a new serialization with the given signature/charset pairs.- Parameters:
signatureCharsets- The pairs.
-
-
Method Detail
-
values
public static Serialization[] 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 (Serialization c : Serialization.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Serialization 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
-
getPrefixMatch
public static SignatureCharset getPrefixMatch(Serialization[] candidates, byte[] data)
Checks whether any of the signatures among the pairs of the given serializations matches the header of the given byte array, and returns the matching signature/charset pair.- Parameters:
candidates- The serializations.data- The byte array.- Returns:
- The matching signature/charset pair, or null if no candidate contains a matching pair. If more than one signature/charset pair is a match, the one with the longest signature is returned; and if there is more than one with the same length, the first such match is returned.
-
decode
public static String decode(Serialization[] candidates, byte[] data) throws I18NException
Decodes the given byte array using the charset paired to a signature (among the pairs of the given serializations) that matches the array header, and returns the result.- Parameters:
candidates- The serializations.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 no match can be found, or if the JVM does not support the charset of the matching signature/charset pair.
-
getSignatureCharsets
public SignatureCharset[] getSignatureCharsets()
Returns the receiver's signature/charset pairs.- Returns:
- The pairs.
-
-