public static void pack(File sourceDir, File targetZip, NameMapper mapper, int compressionLevel) {
    log.debug("Compressing '{}' into '{}'.", sourceDir, targetZip);
    if (!sourceDir.exists()) {
      throw new ZipException("Given file '" + sourceDir + "' doesn't exist!");
    }
    ZipOutputStream out = null;
    try {
      out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZip)));
      out.setLevel(compressionLevel);
      pack(sourceDir, out, mapper, "", true);
    }
    catch (IOException e) {
      throw ZipExceptionUtil.rethrow(e);
    }
    finally {
      IOUtils.closeQuietly(out);
    }
  }
public static void pack ( File sourceDir , File targetZip , NameMapper mapper , int compressionLevel ) { log . debug ( "Compressing '{}' into '{}'." , sourceDir , targetZip ) ; if ( ! sourceDir . exists ( ) ) { throw new ZipException ( "Given file '" + sourceDir + "' doesn't exist!" ) ; } ZipOutputStream out = null ; try { out = new ZipOutputStream ( new BufferedOutputStream ( new FileOutputStream ( targetZip ) ) ) ; out . setLevel ( compressionLevel ) ; pack ( sourceDir , out , mapper , "" , true ) ; } catch ( IOException e ) { throw ZipExceptionUtil . rethrow ( e ) ; } finally { IOUtils . closeQuietly ( out ) ; } }
Compresses the given directory and all its sub-directories into a ZIP file.
<p>
The ZIP file must not be a directory and its parent directory must exist.

@param sourceDir
root directory.
@param targetZip
ZIP file that will be created or overwritten.
@param mapper
call-back for renaming the entries.
@param compressionLevel
compression level