Here you can find the source of search(byte[] needle, byte[] haystack, int from, int to)
public static int search(byte[] needle, byte[] haystack, int from, int to)
//package com.java2s; //License from project: Open Source License public class Main { public static int search(byte[] needle, byte[] haystack, int from, int to) { for (int i = from; i < to - needle.length; i++) { boolean ok = true; for (int j = 0; j < needle.length; j++) { if (needle[j] != haystack[i + j]) { ok = false;/*from w ww . j a va 2s. c o m*/ break; } } if (ok) { return i; } } return -1; } }