public void storeKeys ( Iterator < K > iterator ) { long startedNanos = System . nanoTime ( ) ; FileOutputStream fos = null ; try { buf = allocate ( BUFFER_SIZE ) ; lastWrittenBytes = 0 ; lastKeyCount = 0 ; fos = new FileOutputStream ( tmpStoreFile , false ) ; // write header and keys writeInt ( fos , MAGIC_BYTES ) ; writeInt ( fos , FileFormat . INTERLEAVED_LENGTH_FIELD . ordinal ( ) ) ; writeKeySet ( fos , fos . getChannel ( ) , iterator ) ; // cleanup if no keys have been written if ( lastKeyCount == 0 ) { deleteQuietly ( storeFile ) ; updatePersistenceStats ( startedNanos ) ; return ; } fos . flush ( ) ; closeResource ( fos ) ; rename ( tmpStoreFile , storeFile ) ; updatePersistenceStats ( startedNanos ) ; } catch ( Exception e ) { logger . warning ( format ( "Could not store keys of Near Cache %s (%s)" , nearCacheName , storeFile . getAbsolutePath ( ) ) , e ) ; nearCacheStats . addPersistenceFailure ( e ) ; } finally { closeResource ( fos ) ; deleteQuietly ( tmpStoreFile ) ; } }
Stores the Near Cache keys from the supplied iterator .