public static int findPreamble ( byte [ ] buf , int start , int len ) { int e = start + len - PREAMBLE . length + 1 ; OUTER : for ( int i = start ; i < e ; i ++ ) { if ( buf [ i ] == PREAMBLE [ 0 ] ) { // check for the rest of the match for ( int j = 1 ; j < PREAMBLE . length ; j ++ ) { if ( buf [ i + j ] != PREAMBLE [ j ] ) continue OUTER ; } return i ; // found it } } return - 1 ; // not found }
Locates the preamble in the given buffer .