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 Summary
Fields Modifier and Type Field Description static int
BUFFER_SIZE
The buffer size. -
Constructor Summary
Constructors Constructor Description ZipUtils()
Empty default constructor -
Method Summary
Modifier and Type Method Description static void
addFileToZip(File file, ZipOutputStream out)
Adds a new file to the zip stream.static void
addFileToZip(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize)
Adds a new file to the zip stream.static void
addFileToZip(String subDirectory, File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize)
Adds a new file to the zip stream.static void
addFolderToZip(String folderPath, ZipOutputStream out)
Adds a new entry to the zip file corresponding to a new folder.static void
addToZip(File file, String subDirectory, ZipOutputStream out)
Adds a new file to the zip stream.static void
addToZip(File file, String subDirectory, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize)
Adds a new file to the zip stream.static void
addToZip(File file, ZipOutputStream out)
Adds a new file to the zip stream.static void
addToZip(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize)
Adds a new file to the zip stream.static void
unzip(File zipFile, File destinationFolder, WaitingHandler waitingHandler)
Unzips the content of an archive into a given folder.static void
zip(File originFile, File destinationFile)
Zips a file.static void
zip(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:
- Constant Field Values
-
-
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 IOExceptionZips 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 IOExceptionAdds 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
public static void addToZip(File file, String subDirectory, ZipOutputStream out) throws IOExceptionAdds 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 zipout
- 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 IOExceptionAdds 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 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
public static void addFileToZip(File file, ZipOutputStream out, WaitingHandler waitingHandler, long totalUncompressedFileSize) throws IOExceptionAdds 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 IOExceptionAdds 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 IOExceptionUnzips 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
-