public static void unzipFile ( InputStream input , File output ) throws IOException { if ( output == null ) { return ; } output . mkdirs ( ) ; if ( ! output . isDirectory ( ) ) { throw new IOException ( Locale . getString ( "E3" , output ) ) ; //$NON-NLS-1$ } try ( ZipInputStream zis = new ZipInputStream ( input ) ) { final byte [ ] buffer = new byte [ BUFFER_SIZE ] ; int len ; ZipEntry zipEntry = zis . getNextEntry ( ) ; while ( zipEntry != null ) { final String name = zipEntry . getName ( ) ; final File outFile = new File ( output , name ) . getCanonicalFile ( ) ; if ( zipEntry . isDirectory ( ) ) { outFile . mkdirs ( ) ; } else { outFile . getParentFile ( ) . mkdirs ( ) ; try ( FileOutputStream fos = new FileOutputStream ( outFile ) ) { while ( ( len = zis . read ( buffer ) ) > 0 ) { fos . write ( buffer , 0 , len ) ; } } } zipEntry = zis . getNextEntry ( ) ; } } }
Unzip the given stream and write out the file in the output . If the input file is a directory the content of the directory is zipped . If the input file is a standard file it is zipped .