Package org.marketcetera.util.unicode
Enum Signature
- java.lang.Object
-
- java.lang.Enum<Signature>
-
- org.marketcetera.util.unicode.Signature
-
- All Implemented Interfaces:
Serializable,Comparable<Signature>
public enum Signature extends Enum<Signature>
A byte stream signature. It appears in the beginning (header) of a byte stream, and identifies the charset necessary to interpret the remaining bytes as text.- Since:
- 0.6.0
- Version:
- $Id: Signature.java 16154 2012-07-14 16:34:05Z colin $
- Author:
- tlerios@marketcetera.com
-
-
Field Summary
Fields Modifier and Type Field Description static Signature[]EMPTY_ARRAYprivate byte[]mMark
-
Constructor Summary
Constructors Modifier Constructor Description privateSignature(byte[] mark)Creates a new signature with the given BOM.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetLength()Returns the receiver's BOM length.static intgetLongestLength()Returns the maximum length of any signature BOM.byte[]getMark()Returns the receiver's BOM.static SignaturegetPrefixMatch(Signature[] candidates, byte[] data)Checks whether any of the given signatures matches the header of the given byte array.booleanprefixMatch(byte[] data)Checks whether the receiver's BOM matches the header of the given byte array.static SignaturevalueOf(String name)Returns the enum constant of this type with the specified name.static Signature[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final Signature[] EMPTY_ARRAY
-
mMark
private final byte[] mMark
-
-
Method Detail
-
values
public static Signature[] 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 (Signature c : Signature.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Signature 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
-
getLongestLength
public static int getLongestLength()
Returns the maximum length of any signature BOM.- Returns:
- The length.
-
getPrefixMatch
public static Signature getPrefixMatch(Signature[] candidates, byte[] data)
Checks whether any of the given signatures matches the header of the given byte array.- Parameters:
candidates- The signatures.data- The byte array.- Returns:
- The matching signature, or null if no candidate is a match. If more than one candidate 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.
-
getMark
public byte[] getMark()
Returns the receiver's BOM.- Returns:
- The BOM.
-
getLength
public int getLength()
Returns the receiver's BOM length.- Returns:
- The BOM length.
-
prefixMatch
public boolean prefixMatch(byte[] data)
Checks whether the receiver's BOM matches the header of the given byte array.- Parameters:
data- The byte array.- Returns:
- True if so.
-
-