public static int find(byte[] a,int fromIndex,int toIndex,byte[] key){
  int result=-1;
  int sublen=key.length;
  int maxpos, first, sp=0;
  maxpos=Math.min(toIndex,a.length) - sublen;
  for (first=fromIndex; sp != sublen && first <= maxpos; first++) {
    first=find(a,first,maxpos,key[0]);
    if ((first < 0) || (first > maxpos)) {
      break;
    }
    for (sp=1; sp < sublen; sp++) {
      if (a[first + sp] != key[sp]) {
        sp=sublen;
      }
    }
  }
  if (sublen == 0) {
    result=0;
  }
 else   if (sp == sublen) {
    result=(first - 1);
  }
  return result;
}

public static int find ( byte [ ] a , int fromIndex , int toIndex , byte [ ] key ) { int result = - 1 ; int sublen = key . length ; int maxpos , first , sp = 0 ; maxpos = Math . min ( toIndex , a . length ) - sublen ; for ( first = fromIndex ; sp != sublen && first <= maxpos ; first ++ ) { first = find ( a , first , maxpos , key [ 0 ] ) ; if ( ( first < 0 ) || ( first > maxpos ) ) { break ; } for ( sp = 1 ; sp < sublen ; sp ++ ) { if ( a [ first + sp ] != key [ sp ] ) { sp = sublen ; } } } if ( sublen == 0 ) { result = 0 ; } else if ( sp == sublen ) { result = ( first - 1 ) ; } return result ; }
look for a sequence of bytes in a byte array .
