net.sf.mmm.util.io.api
Enum ByteOrderMark

java.lang.Object
  extended by java.lang.Enum<ByteOrderMark>
      extended by net.sf.mmm.util.io.api.ByteOrderMark
All Implemented Interfaces:
Serializable, Comparable<ByteOrderMark>

public enum ByteOrderMark
extends Enum<ByteOrderMark>

This type represents a Byte-Order-Mark (BOM) of an Unicode-Transformation-Format (UTF).

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Enum Constant Summary
UTF_16_BE
          The ByteOrderMark for UTF-16BE:
0xfe 0xff
UTF_16_LE
          The ByteOrderMark for UTF16-LE:
0xff 0xfe
UTF_32_BE
          The ByteOrderMark for UTF-32BE:
0x00 0x00 0xfe 0xff
UTF_32_LE
          The ByteOrderMark for UTF-32LE:
0xff 0xfe 0x00 0x00
UTF_8
          The ByteOrderMark for UTF-8:
0xef 0xbb 0xbf
 
Field Summary
private static byte[] MAGIC_BYTES_UTF16_BE
           
private static byte[] MAGIC_BYTES_UTF16_LE
           
private static byte[] MAGIC_BYTES_UTF32_BE
           
private static byte[] MAGIC_BYTES_UTF32_LE
           
private static byte[] MAGIC_BYTES_UTF8
           
 
Method Summary
static ByteOrderMark detect(byte[] bytes, int offset)
          This method detects the ByteOrderMark that may be present in the given bytes starting at offset.
protected abstract  byte[] getBytes()
          This method gets the bytes of this BOM.
abstract  String getEncoding()
          This method gets the encoding indicated by this ByteOrderMark.
 int getLength()
          This method gets the number of bytes of this ByteOrderMark.
 boolean isPresent(byte[] bytes, int offset)
          This method detects if this ByteOrderMark is present in the given bytes.
static ByteOrderMark valueOf(String name)
          Returns the enum constant of this type with the specified name.
static ByteOrderMark[] 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

UTF_8

public static final ByteOrderMark UTF_8
The ByteOrderMark for UTF-8:
0xef 0xbb 0xbf


UTF_16_BE

public static final ByteOrderMark UTF_16_BE
The ByteOrderMark for UTF-16BE:
0xfe 0xff


UTF_16_LE

public static final ByteOrderMark UTF_16_LE
The ByteOrderMark for UTF16-LE:
0xff 0xfe


UTF_32_BE

public static final ByteOrderMark UTF_32_BE
The ByteOrderMark for UTF-32BE:
0x00 0x00 0xfe 0xff


UTF_32_LE

public static final ByteOrderMark UTF_32_LE
The ByteOrderMark for UTF-32LE:
0xff 0xfe 0x00 0x00

Field Detail

MAGIC_BYTES_UTF8

private static final byte[] MAGIC_BYTES_UTF8
See Also:
UTF_8

MAGIC_BYTES_UTF16_BE

private static final byte[] MAGIC_BYTES_UTF16_BE
See Also:
UTF_16_BE

MAGIC_BYTES_UTF16_LE

private static final byte[] MAGIC_BYTES_UTF16_LE
See Also:
UTF_16_LE

MAGIC_BYTES_UTF32_BE

private static final byte[] MAGIC_BYTES_UTF32_BE
See Also:
UTF_32_BE

MAGIC_BYTES_UTF32_LE

private static final byte[] MAGIC_BYTES_UTF32_LE
See Also:
UTF_32_LE
Method Detail

values

public static ByteOrderMark[] 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 (ByteOrderMark c : ByteOrderMark.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static ByteOrderMark 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

getEncoding

public abstract String getEncoding()
This method gets the encoding indicated by this ByteOrderMark.

Returns:
the encoding.

getLength

public final int getLength()
This method gets the number of bytes of this ByteOrderMark.

Returns:
the length.

isPresent

public final boolean isPresent(byte[] bytes,
                               int offset)
This method detects if this ByteOrderMark is present in the given bytes.
NOTE:
A BOM may only occur at the head of your data (file, payload, etc.).
ATTENTION:
Please note that binary data may accidently have header bytes that represent this ByteOrderMark. This method can NOT know this and will return true even if the data is NOT encoded with the according encoding. Therefore you should only use this method for the header of textual data.

Parameters:
bytes - is the buffer with the bytes to check.
offset - is the index of the first data-byte in bytes. Will typically be 0.
Returns:
true if this BOM was detected in the

getBytes

protected abstract byte[] getBytes()
This method gets the bytes of this BOM.

Returns:
the magic bytes of this BOM.

detect

public static ByteOrderMark detect(byte[] bytes,
                                   int offset)
This method detects the ByteOrderMark that may be present in the given bytes starting at offset.
ATTENTION:
Please note that binary data may accidently have header bytes that represent a ByteOrderMark. This method can NOT know this and will return that ByteOrderMark even if the data is NOT encoded with the according encoding. Therefore you should only use this method for the header of textual data.

Parameters:
bytes - is the buffer with the bytes to check.
offset - is the index of the first data-byte in bytes. Will typically be 0.
Returns:
the detected ByteOrderMark or null if the given bytes have no BOM.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.