Class ZipUtils

java.lang.Object
com.compomics.util.io.compression.ZipUtils

public class ZipUtils
extends Object
Convenience class for the handling of zip files.
Author:
Marc Vaudel, Harald Barsnes
  • Field Details

  • Constructor Details

    • ZipUtils

      public ZipUtils()
      Empty default constructor
  • Method Details

    • zip

      public static void zip​(File originFile, File destinationFile) throws IOException
      Zips a file.
      Parameters:
      originFile - the file to zip, can be a folder
      destinationFile - the destination file
      Throws:
      IOException - if an IOException occurs
    • zip

      public static void zip​(File originFile, File destinationFile, WaitingHandler waitingHandler, long totalUncompressedFileSize) throws IOException
      Zips a file.
      Parameters:
      originFile - the file to zip, can be a folder
      destinationFile - the destination file
      waitingHandler - a waiting handler allowing canceling the process (can be null)
      totalUncompressedFileSize - the total uncompressed size, a value less than 0 will result in an indeterminate progress bar
      Throws:
      IOException - if an IOException occurs
    • addToZip

      public static void addToZip​(File file, ZipOutputStream out) throws IOException
      Adds a new file to the zip stream. If the file is a folder it will be added with its content.
      Parameters:
      file - the file to add to the zip
      out - the zip stream
      Throws:
      IOException - if an IOException occurs
    • addToZip

      public static void addToZip​(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) throws IOException
      Adds a new file to the zip stream. If the file is a folder it will be added with its content.
      Parameters:
      file - the file to add to the zip
      out - the zip stream
      waitingHandler - a waiting handler allowing canceling the process (can be null)
      totalUncompressedFileSize - the total uncompressed size, a value less than 0 will result in an indeterminate progress bar
      Throws:
      IOException - if an IOException occurs
    • addToZip

      public static void addToZip​(File file, String subDirectory, ZipOutputStream out) throws IOException
      Adds a new file to the zip stream. If the file is a folder it will be added with its content.
      Parameters:
      subDirectory - the subdirectory relative to the zip file location (e.g. "data", note that there is no tailing "/")
      file - the file to add to the zip
      out - the zip stream
      Throws:
      IOException - if an IOException occurs
    • addToZip

      public static void addToZip​(File file, String subDirectory, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) throws IOException
      Adds a new file to the zip stream. If the file is a folder it will be added with its content.
      Parameters:
      subDirectory - the subdirectory relative to the zip file location (e.g. "data", note that there is no tailing "/")
      file - the file to add to the zip
      out - the zip stream
      waitingHandler - a waiting handler allowing canceling the process (can be null)
      totalUncompressedFileSize - the total uncompressed size, a value less than 0 will result in an indeterminate progress bar
      Throws:
      IOException - if an IOException occurs
    • addFileToZip

      public static void addFileToZip​(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) throws IOException
      Adds a new file to the zip stream. The file should not be a folder.
      Parameters:
      file - the file to add to the zip
      out - the zip stream
      waitingHandler - a waiting handler allowing canceling the process (can be null)
      totalUncompressedFileSize - the total uncompressed size, a value less than 0 will result in an indeterminate progress bar
      Throws:
      IOException - if an IOException occurs
    • addFileToZip

      public static void addFileToZip​(File file, ZipOutputStream out) throws IOException
      Adds a new file to the zip stream. The file should not be a folder.
      Parameters:
      file - the file to add to the zip
      out - the zip stream
      Throws:
      IOException - if an IOException occurs
    • addFileToZip

      public static void addFileToZip​(String subDirectory, File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) throws IOException
      Adds a new file to the zip stream. The file should not be a folder.
      Parameters:
      subDirectory - the subdirectory relative to the zip file location (e.g. "data", note that there is no tailing "/")
      file - the file to add to the zip
      out - the zip stream
      waitingHandler - a waiting handler allowing canceling the process (can be null)
      totalUncompressedFileSize - the total uncompressed size, a value less than 0 will result in an indeterminate progress bar
      Throws:
      IOException - if an IOException occurs
    • addFolderToZip

      public static void addFolderToZip​(String folderPath, ZipOutputStream out) throws IOException
      Adds a new entry to the zip file corresponding to a new folder.
      Parameters:
      folderPath - the path to the folder relative to the zip file (e.g. "data", note that there is no tailing "/")
      out - the zip stream
      Throws:
      IOException - if an IOException occurs
    • unzip

      public static void unzip​(File zipFile, File destinationFolder, WaitingHandler waitingHandler) throws IOException
      Unzips the content of an archive into a given folder. The folder needs to exist.
      Parameters:
      zipFile - the file to unzip
      destinationFolder - the destination folder
      waitingHandler - a waiting handler displaying progress and allowing canceling the process (can be null)
      Throws:
      IOException - if an IOException occurs