public long findFirstSet ( long start , byte [ ] temp ) throws IOException { long pos = start >> 3 ; try { lock ( ) . acquireReadLock ( ) ; while ( true ) { int amt = mFile . read ( pos , temp , 0 , temp . length ) ; if ( amt <= 0 ) { return - 1 ; } for ( int i = 0 ; i < amt ; i ++ , pos ++ ) { byte val ; if ( ( val = temp [ i ] ) != 0 ) { long index = pos << 3 ; if ( index < start ) { // Clear the upper bits to skip check. val &= ( 0x000000ff >>> ( start - index ) ) ; if ( val == 0 ) { // False alarm. continue ; } } return index + findSubIndex ( val ) ; } } } } catch ( InterruptedException e ) { throw new InterruptedIOException ( ) ; } finally { lock ( ) . releaseLock ( ) ; } }
Searches the bitlist for the first set bit and returns the index to it .