public static void packEntries(File[] filesToPack, File destZipFile, NameMapper mapper, int compressionLevel) {
    log.debug("Compressing '{}' into '{}'.", filesToPack, destZipFile);

    ZipOutputStream out = null;
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(destZipFile);
      out = new ZipOutputStream(new BufferedOutputStream(fos));
      out.setLevel(compressionLevel);

      for (int i = 0; i < filesToPack.length; i++) {
        File fileToPack = filesToPack[i];

        ZipEntry zipEntry = ZipEntryUtil.fromFile(mapper.map(fileToPack.getName()), fileToPack);
        out.putNextEntry(zipEntry);
        FileUtils.copy(fileToPack, out);
        out.closeEntry();
      }
    }
    catch (IOException e) {
      throw ZipExceptionUtil.rethrow(e);
    }
    finally {
      IOUtils.closeQuietly(out);
      IOUtils.closeQuietly(fos);
    }
  }
public static void packEntries ( File [ ] filesToPack , File destZipFile , NameMapper mapper , int compressionLevel ) { log . debug ( "Compressing '{}' into '{}'." , filesToPack , destZipFile ) ; ZipOutputStream out = null ; FileOutputStream fos = null ; try { fos = new FileOutputStream ( destZipFile ) ; out = new ZipOutputStream ( new BufferedOutputStream ( fos ) ) ; out . setLevel ( compressionLevel ) ; for ( int i = 0 ; i < filesToPack . length ; i ++ ) { File fileToPack = filesToPack [ i ] ; ZipEntry zipEntry = ZipEntryUtil . fromFile ( mapper . map ( fileToPack . getName ( ) ) , fileToPack ) ; out . putNextEntry ( zipEntry ) ; FileUtils . copy ( fileToPack , out ) ; out . closeEntry ( ) ; } } catch ( IOException e ) { throw ZipExceptionUtil . rethrow ( e ) ; } finally { IOUtils . closeQuietly ( out ) ; IOUtils . closeQuietly ( fos ) ; } }
Compresses the given files into a ZIP file.
<p>
The ZIP file must not be a directory and its parent directory must exist.

@param filesToPack
files that needs to be zipped.
@param destZipFile
ZIP file that will be created or overwritten.
@param mapper
call-back for renaming the entries.
@param compressionLevel
ZIP file compression level (speed versus filesize), e.g. <code>Deflater.NO_COMPRESSION</code>, <code>Deflater.BEST_SPEED</code>, or
<code>Deflater.BEST_COMPRESSION</code>