public static FileUtils . FileCopyResult unzip ( final File pulledFile , final File outDir ) throws IOException { if ( ! ( outDir . exists ( ) && outDir . isDirectory ( ) ) ) { throw new ISE ( "outDir[%s] must exist and be a directory" , outDir ) ; } log . info ( "Unzipping file[%s] to [%s]" , pulledFile , outDir ) ; final FileUtils . FileCopyResult result = new FileUtils . FileCopyResult ( ) ; try ( final ZipFile zipFile = new ZipFile ( pulledFile ) ) { final Enumeration < ? extends ZipEntry > enumeration = zipFile . entries ( ) ; while ( enumeration . hasMoreElements ( ) ) { final ZipEntry entry = enumeration . nextElement ( ) ; result . addFiles ( FileUtils . retryCopy ( new ByteSource ( ) { @ Override public InputStream openStream ( ) throws IOException { return new BufferedInputStream ( zipFile . getInputStream ( entry ) ) ; } } , new File ( outDir , entry . getName ( ) ) , FileUtils . IS_EXCEPTION , DEFAULT_RETRY_COUNT ) . getFiles ( ) ) ; } } return result ; }
Unzip the pulled file to an output directory . This is only expected to work on zips with lone files and is not intended for zips with directory structures .