Java String Start With startWithBOM(byte[] array)

Here you can find the source of startWithBOM(byte[] array)

Description

Test if the byte array starts with BOM.

License

LGPL

Parameter

Parameter Description
array byte[], byte array to be tested

Return

true if the array starts with BOM, false if the does not start with BOM

Declaration

public static final boolean startWithBOM(byte[] array) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /** Byte-order mark. */
    private static final String BOM = "\uFEFF";

    /**// w  w w. j a v  a  2 s .  c o m
     * Test if the byte array starts with BOM.
     * 
     * @param array
     *            byte[], byte array to be tested
     * @return <code>true</code> if the array starts with BOM,
     *         <code>false if the {@link String} does not start with BOM
     */
    public static final boolean startWithBOM(byte[] array) {
        if (array.length < 3) {
            return false;
        }
        if ((array[0] != (byte) 0xEF) || (array[1] != (byte) 0xBB) || (array[2] != (byte) 0xBF)) {
            return false;
        }
        return true;
    }

    /**
     * Test if the byte array starts with BOM.
     * 
     * @param text
     *            {@link String}, string to be tested
     * @return <code>true</code> if the string starts with BOM,
     *         <code>false if the {@link String} does not start with BOM
     */
    public static final boolean startWithBOM(String text) {
        return text.startsWith(BOM);
    }
}

Related

  1. startWith(String str, String prefix)
  2. startWith(String str, String start)
  3. startWith(String string, String prefix)
  4. startWith(String string1, String string2)
  5. startWithAorAn(String str)
  6. startWithIgnoreCase(CharSequence str, CharSequence prefix)
  7. startWithIgnoreCase(String str, String prefix)
  8. startWithLowerCase(String in)
  9. startWithLowerCase(String methodName)