Class ZipUtil

java.lang.Object
org.opencastproject.util.ZipUtil

public final class ZipUtil extends Object
Provides static methods for compressing and extracting zip files using zip64 extensions when necessary.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    unzip(File zipFile, File destination)
    Extracts a zip file to a directory.
    static void
    unzip(File zipFile, String destination)
    Extracts a zip file to a directory.
    static void
    unzip(String zipFile, File destination)
    Extracts a zip file to a directory.
    static void
    unzip(String zipFile, String destination)
    Extracts a zip file to a directory.
    static File
    zip(File[] sourceFiles, File destination, boolean recursive, int level)
    Compresses source files into a zip archive
    static File
    zip(File[] sourceFiles, File destination, int level)
    Compresses source files into a zip archive (no recursive)
    static File
    zip(File[] sourceFiles, String destination, boolean recursive, int level)
    Compresses source files into a zip archive
    static File
    zip(String[] sourceFiles, File destination, boolean recursive, int level)
    Compresses source files into a zip archive
    static File
    zip(String[] sourceFiles, String destination, boolean recursive, int level)
    Compresses source files into a zip archive

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • zip

      public static File zip(File[] sourceFiles, File destination, boolean recursive, int level) throws IOException
      Compresses source files into a zip archive
      Parameters:
      sourceFiles - A File array with the files to include in the root of the archive
      destination - A File descriptor to the location where the zip file should be created
      recursive - Indicate whether or not recursively zipping nested directories
      level - The zip algorithm compression level. Ranges between 0 (no compression) and 9 (max. compression)
      Returns:
      A File descriptor of the zip archive file
      Throws:
      IOException - If the zip file can not be created, or the input files names can not be correctly parsed
    • unzip

      public static void unzip(File zipFile, File destination) throws IOException
      Extracts a zip file to a directory.
      Parameters:
      zipFile - A String with the path to the source zip archive
      destination - A String with the location where the zip archive will be extracted. If this destination directory does not exist, it will be created.
      Throws:
      IOException - if the zip file cannot be read, the destination directory cannot be created or the extraction is not successful
    • zip

      public static File zip(String[] sourceFiles, String destination, boolean recursive, int level) throws IOException
      Compresses source files into a zip archive
      Parameters:
      sourceFiles - A String array with the file names to be included in the root of the archive
      destination - A String with the path name of the resulting zip file
      recursive - Indicate whether or not recursively zipping nested directories
      level - The zip algorithm compression level. Ranges between 0 (no compression) and 9 (max. compression)
      Returns:
      A File descriptor of the zip archive file
      Throws:
      IOException - If the zip file can not be created, or the input files names can not be correctly parsed
    • zip

      public static File zip(String[] sourceFiles, File destination, boolean recursive, int level) throws IOException
      Compresses source files into a zip archive
      Parameters:
      sourceFiles - A String array with the file names to be included in the root of the archive
      destination - A File with the path name of the resulting zip file
      recursive - Indicate whether or not recursively zipping nested directories
      level - The zip algorithm compression level. Ranges between 0 (no compression) and 9 (max. compression)
      Returns:
      A File descriptor of the zip archive file
      Throws:
      IOException - If the zip file can not be created, or the input files names can not be correctly parsed
    • zip

      public static File zip(File[] sourceFiles, String destination, boolean recursive, int level) throws IOException
      Compresses source files into a zip archive
      Parameters:
      sourceFiles - A File array with the file names to be included in the root of the archive
      destination - A String with the path name of the resulting zip file
      recursive - Indicate whether or not recursively zipping nested directories
      level - The zip algorithm compression level. Ranges between 0 (no compression) and 9 (max. compression)
      Returns:
      A File descriptor of the zip archive file
      Throws:
      IOException - If the zip file can not be created, or the input files names can not be correctly parsed
    • zip

      public static File zip(File[] sourceFiles, File destination, int level) throws IOException
      Compresses source files into a zip archive (no recursive)
      Parameters:
      sourceFiles - A File array with the file names to be included in the root of the archive
      destination - A File with the path name of the resulting zip file
      level - The zip algorithm compression level. Ranges between 0 (no compression) and 9 (max. compression)
      Returns:
      A File descriptor of the zip archive file
      Throws:
      IOException - If the zip file can not be created, or the input files names can not be correctly parsed
    • unzip

      public static void unzip(String zipFile, String destination) throws IOException
      Extracts a zip file to a directory.
      Parameters:
      zipFile - A String with the path to the source zip archive
      destination - A String with the location where the zip archive will be extracted. If this destination directory does not exist, it will be created.
      Throws:
      IOException - if the zip file cannot be read, the destination directory cannot be created or the extraction is not successful
    • unzip

      public static void unzip(File zipFile, String destination) throws IOException
      Extracts a zip file to a directory.
      Parameters:
      zipFile - A File with the path to the source zip archive
      destination - A String with the location where the zip archive will be extracted.
      Throws:
      IOException - if the zip file cannot be read, the destination directory cannot be created or the extraction is not successful
    • unzip

      public static void unzip(String zipFile, File destination) throws IOException
      Extracts a zip file to a directory.
      Parameters:
      zipFile - A String with the path to the source zip archive
      destination - A File with the location where the zip archive will be extracted.
      Throws:
      IOException - if the zip file cannot be read, the destination directory cannot be created or the extraction is not successful