public static void unzip(InputStream in,Path destDir) throws IOException {
  in=new BufferedInputStream(in);
  try (ZipInputStream zipInput=new ZipInputStream(in)){
    ZipEntry entry;
    byte[] buffer=new byte[8192];
    while ((entry=zipInput.getNextEntry()) != null) {
      Path targetFile=destDir.resolve(entry.getName());
      Files.createDirectories(targetFile.getParent());
      if (!entry.isDirectory()) {
        OutputStream out=Files.newOutputStream(targetFile);
        int len;
        while ((len=zipInput.read(buffer)) >= 0) {
          out.write(buffer,0,len);
        }
        out.close();
      }
      zipInput.closeEntry();
    }
  }
 }

public static void unzip ( InputStream in , Path destDir ) throws IOException { in = new BufferedInputStream ( in ) ; try ( ZipInputStream zipInput = new ZipInputStream ( in ) ) { ZipEntry entry ; byte [ ] buffer = new byte [ 8192 ] ; while ( ( entry = zipInput . getNextEntry ( ) ) != null ) { Path targetFile = destDir . resolve ( entry . getName ( ) ) ; Files . createDirectories ( targetFile . getParent ( ) ) ; if ( ! entry . isDirectory ( ) ) { OutputStream out = Files . newOutputStream ( targetFile ) ; int len ; while ( ( len = zipInput . read ( buffer ) ) >= 0 ) { out . write ( buffer , 0 , len ) ; } out . close ( ) ; } zipInput . closeEntry ( ) ; } } }
convenience method unzipping zipname into destdir . you must pass it a clean destdir . closes the given inputstream after extracting !
