private void rebuildIndex ( ) throws Exception { ByteBuffer buf = ByteBuffer . allocate ( KEY_POS ) ; for ( ; ; ) { // read FileEntry fields from file (size, keyLen etc.) buf . clear ( ) . limit ( KEY_POS ) ; channel . read ( buf , filePos ) ; // return if end of file is reached if ( buf . remaining ( ) > 0 ) return ; buf . flip ( ) ; // initialize FileEntry from buffer int entrySize = buf . getInt ( ) ; int keyLen = buf . getInt ( ) ; int dataLen = buf . getInt ( ) ; int metadataLen = buf . getInt ( ) ; long expiryTime = buf . getLong ( ) ; FileEntry fe = new FileEntry ( filePos , entrySize , keyLen , dataLen , metadataLen , expiryTime ) ; // sanity check if ( fe . size < KEY_POS + fe . keyLen + fe . dataLen + fe . metadataLen ) { throw log . errorReadingFileStore ( file . getPath ( ) , filePos ) ; } // update file pointer filePos += fe . size ; // check if the entry is used or free if ( fe . keyLen > 0 ) { // load the key from file if ( buf . capacity ( ) < fe . keyLen ) buf = ByteBuffer . allocate ( fe . keyLen ) ; buf . clear ( ) . limit ( fe . keyLen ) ; channel . read ( buf , fe . offset + KEY_POS ) ; // deserialize key and add to entries map // Marshaller should allow for provided type return for safety K key = ( K ) ctx . getMarshaller ( ) . objectFromByteBuffer ( buf . array ( ) , 0 , fe . keyLen ) ; entries . put ( key , fe ) ; } else { // add to free list freeList . add ( fe ) ; } } }
Rebuilds the in - memory index from file .