Compresses directory into zip archive.

@param dirName the path to the directory
@param nameZipFile archive name.
@throws IOException
499094
public static void zipDir(String dirName, String nameZipFile) throws IOException {
        try (FileOutputStream fW = new FileOutputStream(nameZipFile);
             ZipOutputStream zip = new ZipOutputStream(fW)) {
            addFolderToZip("", dirName, zip);
        }
    }
697738
public File extractZipEntry(File dir, ZipFile zipFile, ZipEntry entry) throws IOException {
    File outputFile = new File(dir, entry.getName());
    File parentFile = outputFile.getParentFile();
    if (!outputFile.getCanonicalPath().startsWith(dir.getCanonicalPath() + File.separator)
        || (!parentFile.isDirectory() && !parentFile.mkdirs())) {
      throw new IOException("Could not extract " + entry.getName() + " to " + dir.getPath());
    }
    try (InputStream inputStream = zipFile.getInputStream(entry);
        FileOutputStream outputStream = new FileOutputStream(outputFile)) {
      byte[] buf = new byte[1024];
      int n;
      while ((n = inputStream.read(buf)) > 0) {
        outputStream.write(buf, 0, n);
      }
    }
    return outputFile;
  }
1369005
public static byte[] zip(Map<String, List<String>> namesMap, Map<String, List<byte[]>> contentsMap) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // Create the ZIP file
        ZipOutputStream out = new ZipOutputStream(baos);

        for (String folder : namesMap.keySet()) {

            // create the folder
            out.putNextEntry(new ZipEntry(folder + "/"));

            List<String> fileNames = namesMap.get(folder);
            List<byte[]> fileContents = contentsMap.get(folder);

            for (int i = 0, size = fileNames.size(); i < size; i++) {
                String name = fileNames.get(i);
                byte[] content = fileContents.get(i);

                // Add ZIP entry to output stream.
                ZipEntry entry = new ZipEntry(folder + "/" + name);
                entry.setSize(content.length);
                out.putNextEntry(entry);
                out.write(content);
                // Complete the entry
                out.closeEntry();
            }
        }
        out.close();
        return baos.toByteArray();
    }
182912
public static void zip(String destination, String source)
            throws FileNotFoundException, IOException {
        zip(new File(destination), new File(source));
    }
1209484
private void unzip(final File file, final String outputDir) throws IOException {

		try (final ZipFile zipFile = new ZipFile(file)) {

			final Enumeration<? extends ZipEntry> entries = zipFile.entries();

			while (entries.hasMoreElements()) {

				final ZipEntry entry = entries.nextElement();
				final File targetFile = new File(outputDir, entry.getName());

				if (entry.isDirectory()) {

					targetFile.mkdirs();

				} else {

					targetFile.getParentFile().mkdirs();
					InputStream in = zipFile.getInputStream(entry);

					try (OutputStream out = new FileOutputStream(targetFile)) {

						IOUtils.copy(in, out);
						IOUtils.closeQuietly(in);
					}
				}
			}
		}
	}
295452
public static boolean isZip(final String filename)
	{
		for (final String element : FileConst.ZIP_EXTENSIONS)
		{
			if (filename.endsWith(element))
			{
				return true;
			}
		}
		return false;
	}
819436
public static boolean isZip(String fName)
  {
    if (Strings.isNullOrEmpty(fName)) {
      return false;
    }
    return fName.endsWith(ZIP_SUFFIX); // Technically a file named `.zip` would be fine
  }
961194
public void zip(OutputStream os, FileFilter filter) throws IOException, InterruptedException {
        archive(ArchiverFactory.ZIP,os,filter);
    }
79505
public static void zipFile(File input, File output) throws IOException {
		try (FileOutputStream fos = new FileOutputStream(output)) {
			zipFile(input, fos);
		}
	}
1348889
public void deleteFile(String name) throws IOException {
    if (!fs.delete(new Path(directory, name))) {
      throw new IOException("Cannot delete index file " + name);
    }
  }
394498
public static void compress(String fileName, String compressedFileName, String password) {
		try {
			ZipParameters zipParameters = new ZipParameters();
			zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
			zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
			if (password != null) {
				zipParameters.setEncryptFiles(true);
				zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
				zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
				zipParameters.setPassword(password);
			}
			String destinationZipFilePath = compressedFileName;
			ZipFile zipFile = new ZipFile(destinationZipFilePath);
			zipFile.addFile(new File(fileName), zipParameters);
		} catch (ZipException e) {
			JKExceptionUtil.handle(e);
		}
	}
550403
public void extractZipEntry(final ZipFile zipFile, final ZipEntry target,
		final File toDirectory) throws IOException
	{
		ZipExtensions.extractZipEntry(zipFile, target, toDirectory);
	}
420652
public void writeFile(CmsFile file, String name) throws IOException {

        if (m_isExportAsFiles) {
            writeFile2Rfs(file, name);
        } else {
            writeFile2Zip(file, name);
        }
    }
574644
public static void create(String zipFilename, String... filenames)
            throws IOException {

        try (FileSystem zipFileSystem = createZipFileSystem(zipFilename, true)) {
            final Path root = zipFileSystem.getPath("/");

            //iterate over the files we need to add
            for (String filename : filenames) {
                final Path src = Paths.get(filename);

                //add a file to the zip file system
                if(!Files.isDirectory(src)){
                    final Path dest = zipFileSystem.getPath(root.toString(),
                            src.toString());
                    final Path parent = dest.getParent();
                    if(Files.notExists(parent)){
                        if(logger.isDebugEnabled()) logger.debug("Creating directory %s", parent);
                        Files.createDirectories(parent);
                    }
                    Files.copy(src, dest, StandardCopyOption.REPLACE_EXISTING);
                }
                else{
                    //for directories, walk the file tree
                    Files.walkFileTree(src, new SimpleFileVisitor<Path>(){
                        @Override
                        public FileVisitResult visitFile(Path file,
                                                         BasicFileAttributes attrs) throws IOException {
                            final Path dest = zipFileSystem.getPath(root.toString(),
                                    file.toString());
                            Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING);
                            return FileVisitResult.CONTINUE;
                        }

                        @Override
                        public FileVisitResult preVisitDirectory(Path dir,
                                                                 BasicFileAttributes attrs) throws IOException {
                            final Path dirToCreate = zipFileSystem.getPath(root.toString(),
                                    dir.toString());
                            if(Files.notExists(dirToCreate)){
                                if(logger.isDebugEnabled()) logger.debug("Creating directory %s\n", dirToCreate);
                                Files.createDirectories(dirToCreate);
                            }
                            return FileVisitResult.CONTINUE;
                        }
                    });
                }
            }
        }
    }
236479
public ZipExtractor into( File directory ) throws IOException {
		try {
			ensureThatDirectoryExists( directory );
			writeEntriesIntoDirectory(directory);
			return this;
		} catch ( IOException cause ) {
			close();
			throw cause;
		}
	}
1278787
private void zipDirectory(String zipFile, String dirToZip) {
    File directory = new File(dirToZip);
    try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(zipFile))) {
      addDirectoryToZip(directory, directory, stream);
    } catch (Exception e) {
      throw new PlatformManagerException("Failed to zip module", e);
    }
  }
738441
public static void unZipFiles(InputStream inputStream, File outputFolder) throws IOException {
        ZipInputStream zis = new ZipInputStream(inputStream);
        ZipEntry ze = zis.getNextEntry();

        while (ze != null) {
            File file = new File(outputFolder, ze.getName());
            OutputStream os = new BufferedOutputStream(FileUtils.openOutputStream(file));

            try {
                IOUtils.copy(zis, os);
            } finally {
                IOUtils.closeQuietly(os);
            }

            zis.closeEntry();
            ze = zis.getNextEntry();
        }
    }