public static Closeable mountZipExpanded ( InputStream zipData , String zipName , VirtualFile mountPoint , TempFileProvider tempFileProvider ) throws IOException { try { boolean ok = false ; final TempDir tempDir = tempFileProvider . createTempDir ( zipName ) ; try { final File zipFile = File . createTempFile ( zipName + "-" , ".tmp" , tempDir . getRoot ( ) ) ; try { final FileOutputStream os = new FileOutputStream ( zipFile ) ; try { // allow an error on close to terminate the unzip VFSUtils . copyStream ( zipData , os ) ; zipData . close ( ) ; os . close ( ) ; } finally { VFSUtils . safeClose ( zipData ) ; VFSUtils . safeClose ( os ) ; } final File rootFile = tempDir . getRoot ( ) ; VFSUtils . unzip ( zipFile , rootFile ) ; final MountHandle handle = doMount ( new RealFileSystem ( rootFile ) , mountPoint , tempDir ) ; ok = true ; return handle ; } finally { //noinspection ResultOfMethodCallIgnored zipFile . delete ( ) ; } } finally { if ( ! ok ) { VFSUtils . safeClose ( tempDir ) ; } } } finally { VFSUtils . safeClose ( zipData ) ; } }
Create and mount an expanded zip file in a temporary file system returning a single handle which will unmount and close the filesystem when closed . The given zip data stream is closed .