private void checkIndex ( ) throws IOException { boolean isUpToDate = true ; if ( ! isUpToDate ( ) ) { closeFile ( ) ; isUpToDate = false ; } if ( zipRandomFile != null || isUpToDate ) { lastReferenceTimeStamp = System . currentTimeMillis ( ) ; return ; } hasPopulatedData = true ; if ( readIndex ( ) ) { lastReferenceTimeStamp = System . currentTimeMillis ( ) ; return ; } directories = Collections . < RelativeDirectory , DirectoryEntry > emptyMap ( ) ; allDirs = Collections . < RelativeDirectory > emptySet ( ) ; try { openFile ( ) ; long totalLength = zipRandomFile . length ( ) ; ZipDirectory directory = new ZipDirectory ( zipRandomFile , 0L , totalLength , this ) ; directory . buildIndex ( ) ; } finally { if ( zipRandomFile != null ) { closeFile ( ) ; } } lastReferenceTimeStamp = System . currentTimeMillis ( ) ; }
Here we need to make sure that the ZipFileIndex is valid . Check the timestamp of the file and if its the same as the one at the time the index was build we don t need to reopen anything .