public void seek ( long pos ) throws IOException { int n = ( int ) ( real_pos - pos ) ; if ( n >= 0 && n <= buf_end ) { buf_pos = buf_end - n ; } else { raf . seek ( pos ) ; buf_end = 0 ; buf_pos = 0 ; real_pos = raf . getFilePointer ( ) ; } }
If the sought position is within the buffer - simply sets the current buffer position so the next read will be from the buffer . Otherwise seeks in the RAF and reset the buffer end and current positions .