ByteOrderMark.java

package org.europa.together.domain;

import java.util.Arrays;

/**
 * Existing Byte Order Mark (BOM) types.
 */
public enum ByteOrderMark {

    /**
     * None.
     */
    NONE("NONE", new byte[]{}),
    /**
     * UTF-8.
     */
    UTF_8("UTF-8", new byte[]{(byte) 0xEF, (byte) 0xBB, (byte) 0xBF}),
    /**
     * UTF-16 Low Endian.
     */
    UTF_16LE("UTF-16LE", new byte[]{(byte) 0xFF, (byte) 0xFE}),
    /**
     * UTF-16 Big Endian.
     */
    UTF_16BE("UTF-16BE", new byte[]{(byte) 0xFE, (byte) 0xFF}),
    /**
     * UTF-32 Low Endian.
     */
    UTF_32LE("UTF-32LE", new byte[]{(byte) 0xFF, (byte) 0xFE, (byte) 0x00, (byte) 0x00}),
    /**
     * UTF-32 Big Endian.
     */
    UTF_32BE("UTF-32BE", new byte[]{(byte) 0x00, (byte) 0x00, (byte) 0xFE, (byte) 0xFF});

    private final String type;
    private final byte[] value;

    //CONSTRUCTOR
    ByteOrderMark(final String type, final byte[] value) {
        this.type = type;
        this.value = value;
    }

    /**
     * Get the Byte vale for a Byte Order.
     *
     * @return value as Byte
     */
    public byte[] getBytes() {
        byte[] val = Arrays.copyOf(this.value, this.value.length);
        return val;
    }

    @Override
    public String toString() {
        return this.type;
    }
}