Unpacks a ZIP stream to the given directory.
<p>
The output directory must not be a file.

@param is
inputstream for ZIP file.
@param outputDir
output directory (created automatically if not found).
431064
public static void unpack(InputStream is, File outputDir) {
    unpack(is, outputDir, IdentityNameMapper.INSTANCE, null);
  }
587252
public void unzip(final ZipFile zipFile, final File toDir) throws IOException
	{
		ZipExtensions.unzip(zipFile, toDir);
	}
904238
public static void isValidOutputDirectory(File outputDirectory)
			throws InvalidOutputDirectoryException {
		if (!outputDirectory.exists()) {
			outputDirectory.mkdirs();
		}
		if (!outputDirectory.exists()) {
			throw new InvalidOutputDirectoryException("'" + outputDirectory
					+ "' doesn't exist.");
		}
		if (!outputDirectory.isDirectory()) {
			throw new InvalidOutputDirectoryException("'" + outputDirectory
					+ "' is not a directory.");
		}
		if (!outputDirectory.canWrite()) {
			throw new InvalidOutputDirectoryException("Unable to wrote into '"
					+ outputDirectory + "'.");
		}
	}
79505
public static void zipFile(File input, File output) throws IOException {
		try (FileOutputStream fos = new FileOutputStream(output)) {
			zipFile(input, fos);
		}
	}
653088
public static void zipFiles(List<File> files, OutputStream outputStream) throws IOException {
        ZipOutputStream zos = new ZipOutputStream(outputStream);

        for (File file : files) {
            if (file.isDirectory()) {   //if it's a folder
                addFolderToZip("", file, zos);
            } else {
                addFileToZip("", file, zos);
            }
        }

        zos.finish();
    }
582443
def unzip_file_to_dir(path_to_zip, output_directory):
    
    z = ZipFile(path_to_zip, 'r')
    z.extractall(output_directory)
    z.close()
766130
private static void extractDirectory(ZipEntry entry, File dir) throws IOException {
		final String sourceMethod = "extractFile"; //$NON-NLS-1$
		final boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(sourceClass, sourceMethod, new Object[]{entry, dir});
		}

		dir.mkdir();	// May fail if the directory has already been created
		if (!dir.setLastModified(entry.getTime())) {
			throw new IOException("Failed to set last modified time for " + dir.getAbsolutePath()); //$NON-NLS-1$
		}

		if (isTraceLogging) {
			log.exiting(sourceClass, sourceMethod);
		}
	}
983460
private List<File> unzipCorpus(File outDir, ZipFile zip)
  {
    List<File> rootDirs = new ArrayList<>();

    Enumeration<? extends ZipEntry> zipEnum = zip.entries();
    while (zipEnum.hasMoreElements())
    {
      ZipEntry e = zipEnum.nextElement();
      File outFile = new File(outDir, e.getName().replaceAll("\\/", "/"));

      if (e.isDirectory())
      {
        if (!outFile.mkdirs())
        {
          log.warn("Could not create output directory " + outFile.
            getAbsolutePath());
        }
      } // end if directory
      else
      {
        if ("corpus.tab".equals(outFile.getName()) || "corpus.annis".equals(
          outFile.getName()))
        {
          rootDirs.add(outFile.getParentFile());
        }

        if (!outFile.getParentFile().isDirectory())
        {
          if (!outFile.getParentFile().mkdirs())
          {
            {
              log.warn(
                "Could not create output directory for file " + outFile.
                getAbsolutePath());
            }
          }
        }
        try (FileOutputStream outStream = new FileOutputStream(outFile);)
        {

          ByteStreams.copy(zip.getInputStream(e), outStream);
        }
        catch (FileNotFoundException ex)
        {
          log.error(null, ex);
        }
        catch (IOException ex)
        {
          log.error(null, ex);
        }
      } // end else is file
    } // end for each entry in zip file

    return rootDirs;
  }
761275
public static List<File> extract(File zipFile, File outputFolder) throws IOException {
    List<File> extracted = new ArrayList<File>();

    byte[] buffer = new byte[2048];

    if (!outputFolder.exists()) {
      outputFolder.mkdir();
    }

    ZipInputStream zipInput = new ZipInputStream(new FileInputStream(zipFile));

    ZipEntry zipEntry = zipInput.getNextEntry();

    while (zipEntry != null) {

      String neFileNameName = zipEntry.getName();
      File newFile = new File(outputFolder + File.separator + neFileNameName);

      newFile.getParentFile().mkdirs();

      if (!zipEntry.isDirectory()) {
        FileOutputStream fos = new FileOutputStream(newFile);

        int size;
        while ((size = zipInput.read(buffer)) > 0) {
          fos.write(buffer, 0, size);
        }

        fos.close();
        extracted.add(newFile);
      }

      zipEntry = zipInput.getNextEntry();
    }

    zipInput.closeEntry();
    zipInput.close();

    return extracted;

  }
510694
public static void extractDirFromJar(String jarpath, String dir, String destdir) {
        ZipFile zipFile = null;
        try {
            zipFile = new ZipFile(jarpath);
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries != null && entries.hasMoreElements()) {
                ZipEntry ze = entries.nextElement();
                if (!ze.isDirectory() && ze.getName().startsWith(dir)) {
                    InputStream in = zipFile.getInputStream(ze);
                    try {
                        File file = new File(destdir, ze.getName());
                        if (!file.getParentFile().mkdirs()) {
                            if (!file.getParentFile().isDirectory()) {
                                throw new IOException("Mkdirs failed to create " +
                                        file.getParentFile().toString());
                            }
                        }
                        OutputStream out = new FileOutputStream(file);
                        try {
                            byte[] buffer = new byte[8192];
                            int i;
                            while ((i = in.read(buffer)) != -1) {
                                out.write(buffer, 0, i);
                            }
                        } finally {
                            out.close();
                        }
                    } finally {
                        if (in != null)
                            in.close();
                    }
                }
            }
        } catch (Exception e) {
            LOG.warn("No " + dir + " from " + jarpath + "!\n" + e.getMessage());
        } finally {
            if (zipFile != null)
                try {
                    zipFile.close();
                } catch (Exception e) {
                    LOG.warn(e.getMessage());
                }

        }
    }
834119
public static void unzip(final ZipFile zipFile, final File toDir) throws IOException
	{
		try
		{
			for (final Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements();)
			{
				final ZipEntry entry = e.nextElement();
				extractZipEntry(zipFile, entry, toDir);
			}
			zipFile.close();
		}
		catch (final IOException e)
		{
			throw e;
		}
		finally
		{
			zipFile.close();
		}
	}
871121
private void unzipModuleData(File directory, File zipFile, boolean deleteZip) {
    try (InputStream in = new BufferedInputStream(new FileInputStream(zipFile)); ZipInputStream zin = new ZipInputStream(new BufferedInputStream(in))) {
      ZipEntry entry;
      while ((entry = zin.getNextEntry()) != null) {
        String entryName = entry.getName();
        if (!entryName.isEmpty()) {
          if (entry.isDirectory()) {
            File dir = new File(directory, entryName);
            if (!dir.exists()) {
              if (!new File(directory, entryName).mkdir()) {
                throw new PlatformManagerException("Failed to create directory");
              }
            }
          } else {
            int count;
            byte[] buffer = new byte[BUFFER_SIZE];
            BufferedOutputStream out = null;
            try {
              OutputStream os = new FileOutputStream(new File(directory, entryName));
              out = new BufferedOutputStream(os, BUFFER_SIZE);
              while ((count = zin.read(buffer, 0, BUFFER_SIZE)) != -1) {
                out.write(buffer, 0, count);
              }
              out.flush();
            } finally {
              if (out != null) {
                out.close();
              }
            }
          }
        }
      }
    } catch (Exception e) {
      throw new PlatformManagerException("Failed to unzip module", e);
    } finally {
      if (deleteZip) {
        zipFile.delete();
      }
    }
  }
875430
public static void extractFile(final ZipInputStream in, final File outdir, final String name) throws IOException {
        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(outdir, name)));
        int count = -1;
        while ((count = in.read(buffer)) != -1) {
            out.write(buffer, 0, count);
        }
        out.close();
    }
596212
public static void uncompressDirectory(File srcZipPath, File dstDirPath) throws IOException
   {
      ZipInputStream in = new ZipInputStream(new FileInputStream(srcZipPath));
      ZipEntry entry = null;

      try
      {
         while ((entry = in.getNextEntry()) != null)
         {
            File dstFile = new File(dstDirPath, entry.getName());
            dstFile.getParentFile().mkdirs();

            if (entry.isDirectory())
            {
               dstFile.mkdirs();
            }
            else
            {
               OutputStream out = new FileOutputStream(dstFile);
               try
               {
                  transfer(in, out);
               }
               finally
               {
                  out.close();
               }
            }
         }
      }
      finally
      {
         if (in != null)
         {
            in.close();
         }
      }
   }
1352738
public static void unzip(Path zip, Path target) throws IOException {
        try (final ZipFile zipFile = new ZipFile(zip.toFile())){
            unzip(zipFile, target);
        }
    }
179727
public static void copyZipWithoutEmptyDirectories(final File inputFile, final File outputFile) throws IOException
    {
        final byte[] buf = new byte[0x2000];

        final ZipFile inputZip = new ZipFile(inputFile);
        final ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(outputFile));
        try
        {
            // read a the entries of the input zip file and sort them
            final Enumeration<? extends ZipEntry> e = inputZip.entries();
            final ArrayList<ZipEntry> sortedList = new ArrayList<ZipEntry>();
            while (e.hasMoreElements()) {
                final ZipEntry entry = e.nextElement();
                sortedList.add(entry);
            }

            Collections.sort(sortedList, new Comparator<ZipEntry>()
            {
                public int compare(ZipEntry o1, ZipEntry o2)
                {
                    String n1 = o1.getName(), n2 = o2.getName();
                    if (metaOverride(n1, n2)) {
                        return -1;
                    }
                    if (metaOverride(n2, n1)) {
                        return 1;
                    }
                    return n1.compareTo(n2);
                }

                // make sure that META-INF/MANIFEST.MF is always the first entry after META-INF/
                private boolean metaOverride(String n1, String n2) {
                    return (n1.startsWith("META-INF/") && !n2.startsWith("META-INF/"))
                        || (n1.equals("META-INF/MANIFEST.MF") && !n2.equals(n1) && !n2.equals("META-INF/"))
                        || (n1.equals("META-INF/") && !n2.equals(n1));
                }
            });

            // treat them again and write them in output, wenn they not are empty directories
            for (int i = sortedList.size()-1; i>=0; i--)
            {
                final ZipEntry inputEntry = sortedList.get(i);
                final String name = inputEntry.getName();
                final boolean isEmptyDirectory;
                if (inputEntry.isDirectory())
                {
                    if (i == sortedList.size()-1)
                    {
                        // no item afterwards; it was an empty directory
                        isEmptyDirectory = true;
                    }
                    else
                    {
                        final String nextName = sortedList.get(i+1).getName();
                        isEmptyDirectory  = !nextName.startsWith(name);
                    }
                }
                else
                {
                    isEmptyDirectory = false;
                }

                if (isEmptyDirectory)
                {
                    sortedList.remove(i);
                }
            }

            // finally write entries in normal order
            for (int i = 0; i < sortedList.size(); i++)
            {
                final ZipEntry inputEntry = sortedList.get(i);
                final ZipEntry outputEntry = new ZipEntry(inputEntry);
                outputStream.putNextEntry(outputEntry);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final InputStream is = inputZip.getInputStream(inputEntry);
                IoUtil.pipe(is, baos, buf);
                is.close();
                outputStream.write(baos.toByteArray());
            }
        } finally {
            outputStream.close();
            inputZip.close();
        }

    }
1212321
public static File unzip(File inputZip) {
    
    File rootDir = null;
    try {
      BufferedOutputStream dest = null;
      BufferedInputStream is = null;
      ZipEntry entry;
      ZipFile zipfile = new ZipFile(inputZip);
      File test = File.createTempFile("aaa", "aaa");
      String tempDir = test.getParent();
      test.delete();
      Enumeration e = zipfile.entries();
      while (e.hasMoreElements()) {
        entry = (ZipEntry) e.nextElement();
        is = new BufferedInputStream(zipfile.getInputStream(entry));
        int count;
        byte data[] = new byte[BUFFER];
        File target = new File(tempDir, entry.getName());
        if (entry.getName().endsWith("/")) {
          target.mkdir();
          if (rootDir == null) rootDir = target;
          continue;
        }
        FileOutputStream fos = new FileOutputStream(target);
        dest = new BufferedOutputStream(fos, BUFFER);
        while ((count = is.read(data, 0, BUFFER)) != -1) {
          dest.write(data, 0, count);
        }
        dest.flush();
        dest.close();
        is.close();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return rootDir;
  }