Here you can find the source of arraySearch(byte[] array, byte[] search)
public static int arraySearch(byte[] array, byte[] search)
//package com.java2s; //License from project: Open Source License public class Main { public static int arraySearch(byte[] array, byte[] search) { if (search.length == 0) { return -1; }//from www .j a v a 2 s . co m int found = 0; loop: while (true) { found = binarySearch(array, search[0], found + 1); if (found < 0 || found > array.length) { return -1; } for (int i = 1; i < search.length; i++) { try { if (array[found + i] != search[i]) { continue loop; } } catch (ArrayIndexOutOfBoundsException e) { return -1; } } break; } return found; } public static int binarySearch(byte[] a, byte key, int startPos) { if (startPos > a.length || startPos < 0) { return -1; } for (int i = startPos; i < a.length; i++) { if (a[i] == key) { return i; } } return -1; } }