org.marketcetera.util.unicode
Enum Signature

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

Enum Constant Summary
NONE
           
UTF16BE
           
UTF16LE
           
UTF32BE
           
UTF32LE
           
UTF8
           
 
Field Summary
static Signature[] EMPTY_ARRAY
           
 
Method Summary
 int getLength()
          Returns the receiver's BOM length.
static int getLongestLength()
          Returns the maximum length of any signature BOM.
 byte[] getMark()
          Returns the receiver's BOM.
static Signature getPrefixMatch(Signature[] candidates, byte[] data)
          Checks whether any of the given signatures matches the header of the given byte array.
 boolean prefixMatch(byte[] data)
          Checks whether the receiver's BOM matches the header of the given byte array.
static Signature valueOf(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.
 
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

public static final Signature NONE

UTF8

public static final Signature UTF8

UTF16BE

public static final Signature UTF16BE

UTF16LE

public static final Signature UTF16LE

UTF32BE

public static final Signature UTF32BE

UTF32LE

public static final Signature UTF32LE
Field Detail

EMPTY_ARRAY

public static final Signature[] EMPTY_ARRAY
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 name
NullPointerException - 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.


Copyright © 2012. All Rights Reserved.