Class ZipUtils
java.lang.Object
com.compomics.util.io.compression.ZipUtils
Convenience class for the handling of zip files.
- Author:
- Marc Vaudel, Harald Barsnes
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFileToZip(File file, ZipOutputStream out) Adds a new file to the zip stream.static voidaddFileToZip(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) Adds a new file to the zip stream.static voidaddFileToZip(String subDirectory, File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) Adds a new file to the zip stream.static voidaddFolderToZip(String folderPath, ZipOutputStream out) Adds a new entry to the zip file corresponding to a new folder.static voidaddToZip(File file, String subDirectory, ZipOutputStream out) Adds a new file to the zip stream.static voidaddToZip(File file, String subDirectory, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) Adds a new file to the zip stream.static voidaddToZip(File file, ZipOutputStream out) Adds a new file to the zip stream.static voidaddToZip(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) Adds a new file to the zip stream.static voidunzip(File zipFile, File destinationFolder, WaitingHandler waitingHandler) Unzips the content of an archive into a given folder.static voidZips a file.static voidzip(File originFile, File destinationFile, WaitingHandler waitingHandler, long totalUncompressedFileSize) Zips a file.
-
Field Details
-
BUFFER_SIZE
public static final int BUFFER_SIZEThe buffer size.- See Also:
-
-
Constructor Details
-
ZipUtils
public ZipUtils()Empty default constructor
-
-
Method Details
-
zip
Zips a file.- Parameters:
originFile- the file to zip, can be a folderdestinationFile- 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 folderdestinationFile- the destination filewaitingHandler- 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
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 zipout- 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 zipout- the zip streamwaitingHandler- 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
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 zipsubDirectory- the subdirectory relative to the zip file location (e.g. "data", note that there is no tailing "/")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:
file- the file to add to the zipsubDirectory- the subdirectory relative to the zip file location (e.g. "data", note that there is no tailing "/")out- the zip streamwaitingHandler- 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 zipout- the zip streamwaitingHandler- 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
Adds a new file to the zip stream. The file should not be a folder.- Parameters:
file- the file to add to the zipout- 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 zipout- the zip streamwaitingHandler- 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
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 unzipdestinationFolder- the destination folderwaitingHandler- a waiting handler displaying progress and allowing canceling the process (can be null)- Throws:
IOException- if an IOException occurs
-