Java Array Starts With startsWith(byte[] bytes, int offset, byte... prefix)

Here you can find the source of startsWith(byte[] bytes, int offset, byte... prefix)

Description

starts With

License

Apache License

Declaration

public static boolean startsWith(byte[] bytes, int offset, byte... prefix) 

Method Source Code

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

public class Main {

    public static boolean startsWith(byte[] bytes, int offset, byte... prefix) {
        if (length(bytes) == 0 || length(prefix) == 0 || prefix.length > bytes.length || offset < 0
                || offset + prefix.length > bytes.length) {
            return false;
        }//from w  ww  .  j  av  a  2 s.c  o m

        for (int i = 0; i < prefix.length; i++) {
            if (prefix[i] != bytes[i + offset]) {
                return false;
            }
        }

        return true;
    }

    public static int length(byte[] array) {
        return (array == null ? 0 : array.length);
    }

    public static int length(byte[]... arrays) {
        int len = 0;
        if (arrays != null) {
            for (byte[] array : arrays) {
                if (array != null) {
                    len += array.length;
                }
            }
        }

        return len;
    }
}

Related

  1. startsWith(byte a[], int from, byte b[])
  2. startsWith(byte[] arr, int offset, int len, byte[] pattern)
  3. startsWith(byte[] array, byte[] prefix)
  4. startsWith(byte[] array, byte[] startBytes)
  5. startsWith(byte[] bytes, String str, int offset)
  6. startsWith(byte[] bytes, String text)
  7. startsWith(byte[] checkMe, byte[] maybePrefix)
  8. startsWith(byte[] haystack, byte[] needle)