net.sf.okapi.common

## Class ZipUtil

- java.lang.Object
- - net.sf.okapi.common.ZipUtil

-     public class ZipUtil
      extends java.lang.Object

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ZipUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `safeUnzip(java.nio.file.Path zipFile, java.nio.file.Path unzipDirectory)` Convenience method.
    `static void` | `safeUnzip(java.util.zip.ZipInputStream zis, java.nio.file.Path unzipDirectory)` Extract a ZipInputStream to the target destination directory.
    `static void` | `zipDirectory(java.lang.String sourceDir, java.lang.String zipExtension)` Compresses a given directory.
    `static void` | `zipDirectory(java.lang.String sourceDir, java.lang.String zipExtension, java.lang.String destinationPathWithoutExtension)` Compresses a given directory.
    `static void` | `zipFiles(java.lang.String zipPath, java.lang.String sourceDir, java.lang.String... filenames)` Creates a ZIP file and adds a list of files in it.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ZipUtil

          public ZipUtil()

  - ### Method Detail

    - #### safeUnzip

          public static void safeUnzip(java.util.zip.ZipInputStream zis,
                                       java.nio.file.Path unzipDirectory)
                                throws java.io.IOException

      Extract a ZipInputStream to the target destination directory. Does not allow malicious ZIP packages to escape from the prescribed directory tree.
      Parameters:
        `zis` -
        `unzipDirectory` -
      Throws:
        `java.io.IOException`

    - #### safeUnzip

          public static void safeUnzip(java.nio.file.Path zipFile,
                                       java.nio.file.Path unzipDirectory)
                                throws java.io.IOException

      Convenience method.
      Parameters:
        `zipFile` -
        `unzipDirectory` -
      Throws:
        `java.io.IOException`

    - #### zipDirectory

          public static void zipDirectory(java.lang.String sourceDir,
                                          java.lang.String zipExtension)

      Compresses a given directory. Creates in the same parent folder a ZIP file with the folder name as the file name and a given extension. The given directory is not deleted after compression.

      This method uses the Java ZIP package and does not supports files to zip that have a path with extended characters.

      Parameters:
        `sourceDir` - the given directory to be compressed
        `zipExtension` - an extension for the output ZIP file (default is .zip if a null or empty string is passed by the caller). The extension is expected to contain the leading period.

    - #### zipDirectory

          public static void zipDirectory(java.lang.String sourceDir,
                                          java.lang.String zipExtension,
                                          java.lang.String destinationPathWithoutExtension)

      Compresses a given directory. The given directory is not deleted after compression.

      This method uses the Java ZIP package and does not supports files to zip that have a path with extended characters.

      Parameters:
        `sourceDir` - the given directory to be compressed
        `zipExtension` - an extension for the output ZIP file (default is .zip if a null or empty string is passed by the caller). The extension is expected to contain the leading period.
        `destinationPathWithoutExtension` - output path of the zip file, without extension. Use null to use the source directory path.

    - #### zipFiles

          public static void zipFiles(java.lang.String zipPath,
                                      java.lang.String sourceDir,
                                      java.lang.String... filenames)

      Creates a ZIP file and adds a list of files in it.
      Parameters:
        `zipPath` - the path of the ZIP file to create.
        `sourceDir` - the path of the directory where the source files are located.
        `filenames` - the list of files to zip.