Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2015 Santhosh Kumar Tekuri The JLibs authors license this file to you under the Apache License, version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package jlibs.nbp;


Santhosh Kumar T
public enum BOM{
    UTF8        ("UTF-8"               , new int[]{0xEF, 0xBB, 0xBF}      , null),
    UCS4_LE     ("UCS-4LE"             , new int[]{0xFF, 0xFE, 0x00, 0x00}, new int[]{0x3C, 0x00, 0x00, 0x00}),
    UCS4_BE     ("UCS-4BE"             , new int[]{0x00, 0x00, 0xFE, 0xFF}, new int[]{0x00, 0x00, 0x00, 0x3C}),
    UCS4_2143   ("UCS-4-2143"          , new int[]{0x00, 0x00, 0xFF, 0xFE}, new int[]{0x00, 0x00, 0x3C, 0x00}),
    UCS4_3412   ("UCS-4-3412"          , new int[]{0xFE, 0xFF, 0x00, 0x00}, new int[]{0x00, 0x3C, 0x00, 0x00}),
    UTF16_LE    ("UTF-16LE"            , new int[]{0xFF, 0xFE}            , new int[]{0x3C, 0x00, 0x3F, 0x00}),
    UTF16_BE    ("UTF-16BE"            , new int[]{0xFE, 0xFF}            , new int[]{0x00, 0x3C, 0x00, 0x3F}),
    ASCII       ("UTF-8"               , null                             , new int[]{0x3C, 0x3F, 0x78, 0x6D}),
    EBCDIC      ("Cp037"               , null                             , new int[]{0x4C, 0x6F, 0xA7, 0x94}),
    private String encoding;
    private byte with[];
    private byte without[];
    BOM(String encodingint[] withint[] without){
        this. = encoding;
        this. = toBytes(with);
        this. = toBytes(without);
    private static byte[] toBytes(int[] arr){
            return null;
            byte b[] = new byte[arr.length];
            for(int i=0; i<arr.lengthi++)
                b[i] = (byte)arr[i];
            return b;
    public String encoding(){
        return ;
    public byte[] with(){
        return ;
    public byte[] without(){
        return ;
    public static BOM get(byte b[], boolean with){
        for(BOM bom : values()){
            byte expected[] = with ? bom.with() : bom.without();
            if(expected!=null && b.length>=expected.length){
                boolean matched = true;
                for(int i=0; i<expected.lengthi++){
                        matched = false;
                    return bom;
        return null;
New to GrepCode? Check out our FAQ X