Package org.marketcetera.util.unicode
Enum DecodingStrategy
- java.lang.Object
-
- java.lang.Enum<DecodingStrategy>
-
- org.marketcetera.util.unicode.DecodingStrategy
-
- All Implemented Interfaces:
Serializable,Comparable<DecodingStrategy>
public enum DecodingStrategy extends Enum<DecodingStrategy>
A list of one or moreSerializationinstances. This list (indirectly) defines a sequence of signatures that we attempt to match (in order) against a byte array header, and the associated charset we should use if a match is found.- Since:
- 0.6.0
- Version:
- $Id: DecodingStrategy.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Enum Constant Summary
Enum Constants Enum Constant Description SIG_REQUTF16_DEFAULTUTF32_DEFAULTUTF8_DEFAULT
-
Field Summary
Fields Modifier and Type Field Description private Serialization[]mSerializations
-
Constructor Summary
Constructors Modifier Constructor Description privateDecodingStrategy(Serialization[] serializations)Creates a new charset with the given serializations.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringdecode(byte[] data)Decodes the given byte array using the charset paired to a signature (among the signature/charset pairs within the receiver's serializations) that matches the array header, and returns the result.SignatureCharsetgetPrefixMatch(byte[] data)Checks whether any of the signatures among the signature/charset pairs within the receiver's serializations matches the header of the given byte array, and returns the matching pair.Serialization[]getSerializations()Returns the receiver's serializations.static DecodingStrategyvalueOf(String name)Returns the enum constant of this type with the specified name.static DecodingStrategy[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
UTF8_DEFAULT
public static final DecodingStrategy UTF8_DEFAULT
-
UTF16_DEFAULT
public static final DecodingStrategy UTF16_DEFAULT
-
UTF32_DEFAULT
public static final DecodingStrategy UTF32_DEFAULT
-
SIG_REQ
public static final DecodingStrategy SIG_REQ
-
-
Field Detail
-
mSerializations
private final Serialization[] mSerializations
-
-
Constructor Detail
-
DecodingStrategy
private DecodingStrategy(Serialization[] serializations)
Creates a new charset with the given serializations.- Parameters:
serializations- The serializations.
-
-
Method Detail
-
values
public static DecodingStrategy[] 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 (DecodingStrategy c : DecodingStrategy.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DecodingStrategy 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
-
getSerializations
public Serialization[] getSerializations()
Returns the receiver's serializations.- Returns:
- The serializations.
-
getPrefixMatch
public SignatureCharset getPrefixMatch(byte[] data)
Checks whether any of the signatures among the signature/charset pairs within the receiver's serializations matches the header of the given byte array, and returns the matching pair.- Parameters:
data- The byte array.- Returns:
- The matching signature/charset pair, or null if no serialization contains a match. 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 String decode(byte[] data) throws I18NException
Decodes the given byte array using the charset paired to a signature (among the signature/charset pairs within the receiver's serializations) that matches the array header, and returns the result.- 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 no match can be found, or if the JVM does not support the charset of the matching signature/charset pair.
-
-