public void remap ( ) throws IOException { if ( _mmapArray == null ) { open ( ) ; return ; } long length = _raf . length ( ) ; long mappedLength = getMappedLength ( ) ; if ( length != mappedLength ) { // Allocate mapped buffer array int cnt = 0 ; long position = 0 ; cnt = ( int ) ( length >> BUFFER_BITS ) ; cnt += ( length & BUFFER_MASK ) > 0 ? 1 : 0 ; MappedByteBuffer [ ] mmapArray = new MappedByteBuffer [ cnt ] ; int sharedCnt = Math . min ( mmapArray . length , _mmapArray . length ) - 1 ; for ( int i = 0 ; i < sharedCnt ; i ++ ) { mmapArray [ i ] = _mmapArray [ i ] ; position += BUFFER_SIZE ; } // Create individual mapped buffers for ( int i = sharedCnt ; i < cnt ; i ++ ) { long size = Math . min ( length - position , BUFFER_SIZE ) ; mmapArray [ i ] = _raf . getChannel ( ) . map ( FileChannel . MapMode . READ_ONLY , position , size ) ; position += BUFFER_SIZE ; } // Rest mapped buffer array _mmapArray = mmapArray ; // Set current position to 0 _currentPosition = 0 ; } }
Performs re - mapping operation to synchronize with the underling file .