Utility function to zip the content of an entire folder, but not the folder itself.
@param folder
@param fileName optional
@return success or not
175040
public static boolean zipFolder(File folder, String fileName){
		boolean success = false;
		if(!folder.isDirectory()){
			return false;
		}
		
		if(fileName == null){
			fileName = folder.getAbsolutePath()+ZIP_EXT;
		}
		
		ZipArchiveOutputStream zipOutput = null;
		try {
			zipOutput = new ZipArchiveOutputStream(new File(fileName));
			
			success = addFolderContentToZip(folder,zipOutput,"");

			zipOutput.close();
		
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		finally{
			try {
				if(zipOutput != null){
					zipOutput.close();
				}
			} catch (IOException e) {}
		}
		return success;
	}
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);
					}
				}
			}
		}
	}
739344
private static function folderToZip($folder, &$zipFile, $parentPath) {
		
		$handle = opendir($folder);
		
		while (false !== $f = readdir($handle)) {
			
			// list of unwanted files
			$excluded = array('.', '..', '.DS_Store', 'thumbs.db');
			
			if (!in_array($f, $excluded)) {
				
				$filePath = $folder . '/' . $f;
				
				// removes prefix from file path before add to zip
				if (0 === strpos($filePath, $parentPath)) {
					$localPath = substr($filePath, strlen($parentPath . '/'));
				} 
				
				if (is_file($filePath)) {
					
					$zipFile->addFile($filePath, $localPath);
					
				} elseif (is_dir($filePath)) {
					
					// adds sub-directory
					$zipFile->addEmptyDir($localPath);
					self::folderToZip($filePath, $zipFile, $parentPath);
				}
				
			}
			
		}
		
		closedir($handle);
		
	}
103699
public void removeFolder(String folder) {

        m_searchObject.removeFolder(folder);
        m_searchObjectChanged = true;
        ValueChangeEvent.fire(this, m_searchObject);
    }
1005738
public HttpServerBuilder contentFrom(final String contextRoot, final TemporaryFolder folder) {
        resources.put(contextRoot, folder);
        return this;
    }
941717
private void mapFilesInZip(String fileName) {
		File file = new File(fileName);
		fileCreationTimes.put(file, new Long(file.lastModified()));

		ZipFile zipfile;
		try {
			zipfile = new ZipFile(fileName);
		} catch (IOException ioe) {
			throw new NoClassDefFoundError("class location '" + fileName + "' can not be accessed by classloader: " + ioe);
		}
		Enumeration<? extends ZipEntry> e = zipfile.entries();
		while (e.hasMoreElements()) {
			ZipEntry entry = e.nextElement();
			if (!entry.isDirectory()) {
				mapClassResourceEntry(entry.getName(), fileName);
			}
		}
		try {
			zipfile.close();
		} catch (IOException ioe) {
			throw new NoClassDefFoundError("class fileName '" + fileName + "' can not be accessed by classloader: " + ioe);
		}
	}
664105
public static void compress(int format, Resource source, Resource target, boolean includeBaseFolder, int mode) throws IOException {
	if (format == FORMAT_GZIP) compressGZip(source, target);
	else if (format == FORMAT_BZIP2) compressBZip2(source, target);
	else {
	    Resource[] sources = (!includeBaseFolder && source.isDirectory()) ? source.listResources() : new Resource[] { source };
	    compress(format, sources, target, mode);
	}
    }
1328171
public static File compressFileGzip(String _sourceFile, String _outputFileName) {
        return compress(CompressionMethod.GZIP, _sourceFile, _outputFileName);
    }
1043889
public void unzip(String zipFilePath, String destDirectory) throws IOException {
        File destDir = new File(destDirectory);
        if (!destDir.exists()) {
            destDir.mkdir();
        }
        ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
        ZipEntry entry = zipIn.getNextEntry();
        while (entry != null) {
            File destFile = new File(destDir, entry.getName());
            long lastModified = entry.getTime();
            if (!entry.isDirectory()) {
                extractFile(zipIn, destFile);
                if (lastModified != -1) {
                    destFile.setLastModified(entry.getTime());
                }
            } else {
                destFile.mkdir();
            }
            zipIn.closeEntry();
            entry = zipIn.getNextEntry();
        }
        zipIn.close();
    }
90643
public static function folderToZip($folder, &$zipFile, $exclusiveLength, $exclude = array('.git'), $prefix = '') {
	if (!file_exists($folder)) return;
    $handle = opendir($folder);
    while (false !== $f = readdir($handle)) {
      if ($f != '.' && $f != '..') {
		  
		if (in_array($f, $exclude)) continue;
		  
        $filePath = "$folder/$f";
        // Remove prefix from file path before add to zip.
        $localPath = $prefix.substr($filePath, $exclusiveLength);
        if (is_file($filePath)) {
          $zipFile->addFile($filePath, $localPath);
        } elseif (is_dir($filePath)) {
          // Add sub-directory.
          $zipFile->addEmptyDir($localPath);
          self::folderToZip($filePath, $zipFile, $exclusiveLength, $exclude, $prefix);
        }
      }
    }
    closedir($handle);
  }
805893
def CopyFileInZip(from_zip, from_name, to_zip, to_name=None):
  """"""
  data = from_zip.read(from_name)
  if to_name is None:
    to_name = from_name
  to_zip.writestr(to_name, data)
604366
public static void zipCompress(String filename) throws IOException {
    FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX);
    CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32());
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum));
    out.setComment("Failmon records.");

    BufferedReader in = new BufferedReader(new FileReader(filename));
    out.putNextEntry(new ZipEntry(new File(filename).getName()));
    int c;
    while ((c = in.read()) != -1)
      out.write(c);
    in.close();

    out.finish();
    out.close();
  }
444783
public Optional<ZipErrorCodes> zip()
	{
		try (FileOutputStream fos = new FileOutputStream(this.zipFile);
			ZipOutputStream zos = new ZipOutputStream(fos);)
		{

			if (!this.directoryToZip.exists())
			{
				return Optional.of(ZipErrorCodes.DIRECTORY_TO_ZIP_DOES_NOT_EXIST);
			}
			if (!this.zipFile.exists())
			{
				return Optional.of(ZipErrorCodes.ZIP_FILE_DOES_NOT_EXIST);
			}
			if (0 < this.zipLevel)
			{
				zos.setLevel(this.zipLevel);
			}
			else
			{
				zos.setLevel(9);
			}
			if (null != this.zipFileComment)
			{
				zos.setComment(this.zipFileComment);
			}
			if (0 < this.compressionMethod)
			{
				zos.setMethod(this.compressionMethod);
			}
			this.zipFiles(this.directoryToZip, zos);
			zos.flush();
			zos.finish();
			fos.flush();
		}
		catch (IOException e)
		{
			log.log(Level.SEVERE, e.getLocalizedMessage(), e);
			return Optional.of(ZipErrorCodes.IO_ERROR);
		}
		return Optional.empty();
	}
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);
        }
    }
127137
public static void extractZipFile(final String path, final File dest, final String fileName) throws IOException {
        FilenameFilter filter = null;
        if (null != fileName) {
            filter = new FilenameFilter() {
                public boolean accept(final File file, final String name) {
                    return fileName.equals(name) || fileName.startsWith(name);
                }
            };
        }
        extractZip(path, dest, filter, null, null);
    }
162100
public static Map<String, byte[]> unzipFile(final byte[] zipBytes, boolean stripZIPName) throws IOException {
        final Map<ZipEntry, byte[]> zipEntries = new HashMap<ZipEntry, byte[]>();
        final ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipBytes));
        ZipEntry entry = null;
        byte[] buffer = new byte[1024];
        int read;
        while ((entry = zis.getNextEntry()) != null) {
            final ByteArrayOutputStream bos = new ByteArrayOutputStream();
            while ((read = zis.read(buffer)) > 0) {
                bos.write(buffer, 0, read);
            }
            zipEntries.put(entry, bos.toByteArray());
        }

        final HashMap<String, byte[]> files = new HashMap<String, byte[]>();
        for (final Entry<ZipEntry, byte[]> mapEntry : zipEntries.entrySet()) {
            final ZipEntry zipEntry = mapEntry.getKey();
            // Ignore directories, as we only want files
            if (!zipEntry.isDirectory()) {
                if (stripZIPName) {
                    files.put(stripZipFileName(zipEntry.getName()), mapEntry.getValue());
                } else {
                    files.put(zipEntry.getName(), mapEntry.getValue());
                }
            }
        }

        return files;
    }
937035
public static void explode(File zip) {
    try {
      // Find a new unique name is the same directory
      File tempFile = FileUtils.getTempFileFor(zip);

      // Rename the archive
      FileUtils.moveFile(zip, tempFile);

      // Unpack it
      unpack(tempFile, zip);

      // Delete the archive
      if (!tempFile.delete()) {
        throw new IOException("Unable to delete file: " + tempFile);
      }
    }
    catch (IOException e) {
      throw ZipExceptionUtil.rethrow(e);
    }
  }