public class ZipFile extends Object implements Closeable
| Constructor and Description |
|---|
ZipFile(File zipFile)
Creates a new Zip File Object with the input file.
|
ZipFile(File zipFile,
char[] password)
Creates a new Zip File Object with the input file.
|
ZipFile(String zipFile)
Creates a new ZipFile instance with the zip file at the location specified in zipFile.
|
ZipFile(String zipFile,
char[] password)
Creates a new ZipFile instance with the zip file at the location specified in zipFile.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addFile(File fileToAdd)
Adds input source file to the zip file with default zip parameters.
|
void |
addFile(File fileToAdd,
ZipParameters parameters)
Adds input source file to the zip file.
|
void |
addFile(String fileToAdd)
Adds input source file to the zip file with default zip parameters.
|
void |
addFile(String fileToAdd,
ZipParameters zipParameters)
Adds input source file to the zip file with provided zip parameters.
|
void |
addFiles(List<File> filesToAdd)
Adds the list of input files to the zip file with default zip parameters.
|
void |
addFiles(List<File> filesToAdd,
ZipParameters parameters)
Adds the list of input files to the zip file.
|
void |
addFolder(File folderToAdd)
Adds the folder in the given file object to the zip file with default zip parameters.
|
void |
addFolder(File folderToAdd,
ZipParameters zipParameters)
Adds the folder in the given file object to the zip file.
|
void |
addStream(InputStream inputStream,
ZipParameters parameters)
Creates a new entry in the zip file and adds the content of the input stream to the
zip file.
|
void |
close()
Closes any open streams that were open by an instance of this class.
|
void |
createSplitZipFile(List<File> filesToAdd,
ZipParameters parameters,
boolean splitArchive,
long splitLength)
Creates a zip file and adds the list of source file(s) to the zip file.
|
void |
createSplitZipFileFromFolder(File folderToAdd,
ZipParameters parameters,
boolean splitArchive,
long splitLength)
Creates a zip file and adds the files/folders from the specified folder to the zip file.
|
void |
extractAll(String destinationPath)
Extracts all the files in the given zip file to the input destination path.
|
void |
extractAll(String destinationPath,
UnzipParameters unzipParameters)
Extracts all entries in the zip file to the destination path considering the options defined in
UnzipParameters
|
void |
extractFile(FileHeader fileHeader,
String destinationPath)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(FileHeader fileHeader,
String destinationPath,
String newFileName)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(FileHeader fileHeader,
String destinationPath,
String newFileName,
UnzipParameters unzipParameters)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(FileHeader fileHeader,
String destinationPath,
UnzipParameters unzipParameters)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(String fileName,
String destinationPath)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(String fileName,
String destinationPath,
String newFileName)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(String fileName,
String destinationPath,
String newFileName,
UnzipParameters unzipParameters)
Extracts a specific file from the zip file to the destination path.
|
void |
extractFile(String fileName,
String destinationPath,
UnzipParameters unzipParameters)
Extracts a specific file from the zip file to the destination path.
|
int |
getBufferSize()
Returns the size of the buffer used to read streams
|
Charset |
getCharset()
Returns user defined charset that was set by setCharset() method.
|
String |
getComment()
Returns the comment set for the Zip file
|
ExecutorService |
getExecutorService() |
File |
getFile() |
FileHeader |
getFileHeader(String fileName)
Returns FileHeader if a file header with the given fileHeader
string exists in the zip model: If not returns null
|
List<FileHeader> |
getFileHeaders()
Returns the list of file headers in the zip file.
|
ZipInputStream |
getInputStream(FileHeader fileHeader)
Returns an input stream for reading the contents of the Zip file corresponding
to the input FileHeader.
|
ProgressMonitor |
getProgressMonitor() |
List<File> |
getSplitZipFiles()
Returns the full file path+names of all split zip files
in an ArrayList.
|
boolean |
isEncrypted()
Checks to see if the zip file is encrypted
|
boolean |
isRunInThread() |
boolean |
isSplitArchive()
Checks if the zip file is a split archive
|
boolean |
isValidZipFile()
Checks to see if the input zip file is a valid zip file.
|
void |
mergeSplitFiles(File outputZipFile)
Merges split zip files into a single zip file without the need to extract the
files in the archive
|
void |
removeFile(FileHeader fileHeader)
Removes the file provided in the input file header from the zip file.
|
void |
removeFile(String fileName)
Removes the file provided in the input parameters from the zip file.
|
void |
removeFiles(List<String> fileNames)
Removes all files from the zip file that match the names in the input list.
|
void |
renameFile(FileHeader fileHeader,
String newFileName)
Renames file name of the entry represented by file header.
|
void |
renameFile(String fileNameToRename,
String newFileName)
Renames file name of the entry represented by input fileNameToRename.
|
void |
renameFiles(Map<String,String> fileNamesMap)
Renames all the entries in the zip file that match the keys in the map to their corresponding values in the map.
|
void |
setBufferSize(int bufferSize)
Sets the size of buffer that should be used when reading streams.
|
void |
setCharset(Charset charset)
Sets the charset to be used for encoding file names and comments
|
void |
setComment(String comment)
Sets comment for the Zip file
|
void |
setPassword(char[] password)
Sets a password to be used for the zip file.
|
void |
setRunInThread(boolean runInThread) |
void |
setThreadFactory(ThreadFactory threadFactory) |
String |
toString() |
public ZipFile(String zipFile)
zipFile - public ZipFile(String zipFile, char[] password)
zipFile - public ZipFile(File zipFile)
zipFile - file reference to the zip fileIllegalArgumentException - when zip file parameter is nullpublic ZipFile(File zipFile, char[] password)
zipFile - file reference to the zip filepassword - password to use for the zip fileIllegalArgumentException - when zip file parameter is nullpublic void createSplitZipFile(List<File> filesToAdd, ZipParameters parameters, boolean splitArchive, long splitLength) throws ZipException
filesToAdd - - File to be added to the zip fileparameters - - zip parameters for this file listsplitArchive - - if archive has to be split or notsplitLength - - if archive has to be split, then length in bytes at which it has to be splitZipExceptionpublic void createSplitZipFileFromFolder(File folderToAdd, ZipParameters parameters, boolean splitArchive, long splitLength) throws ZipException
folderToAdd - parameters - splitArchive - splitLength - ZipExceptionpublic void addFile(String fileToAdd) throws ZipException
fileToAdd - - File with path to be added to the zip fileZipExceptionpublic void addFile(String fileToAdd, ZipParameters zipParameters) throws ZipException
fileToAdd - - File with path to be added to the zip filezipParameters - - parameters for the entry to be added to zipZipExceptionpublic void addFile(File fileToAdd) throws ZipException
fileToAdd - - File to be added to the zip fileZipExceptionpublic void addFile(File fileToAdd, ZipParameters parameters) throws ZipException
fileToAdd - - File to be added to the zip fileparameters - - zip parameters for this fileZipExceptionpublic void addFiles(List<File> filesToAdd) throws ZipException
filesToAdd - ZipExceptionpublic void addFiles(List<File> filesToAdd, ZipParameters parameters) throws ZipException
filesToAdd - parameters - ZipExceptionpublic void addFolder(File folderToAdd) throws ZipException
folderToAdd - ZipExceptionpublic void addFolder(File folderToAdd, ZipParameters zipParameters) throws ZipException
folderToAdd - zipParameters - ZipExceptionpublic void addStream(InputStream inputStream, ZipParameters parameters) throws ZipException
inputStream - parameters - ZipExceptionpublic void extractAll(String destinationPath) throws ZipException
destinationPath - path to which the entries of the zip are to be extractedZipException - when an issue occurs during extractionpublic void extractAll(String destinationPath, UnzipParameters unzipParameters) throws ZipException
destinationPath - path to which the entries of the zip are to be extractedunzipParameters - parameters to be considered during extractionZipException - when an issue occurs during extractionpublic void extractFile(FileHeader fileHeader, String destinationPath) throws ZipException
fileHeader - file header corresponding to the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractedZipException - when an issue occurs during extractionpublic void extractFile(FileHeader fileHeader, String destinationPath, UnzipParameters unzipParameters) throws ZipException
fileHeader - file header corresponding to the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractedunzipParameters - any parameters that have to be considered during extractionZipException - when an issue occurs during extractionpublic void extractFile(FileHeader fileHeader, String destinationPath, String newFileName, UnzipParameters unzipParameters) throws ZipException
fileHeader - file header corresponding to the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractednewFileName - if not null, this will be the name given to the file upon extractionunzipParameters - any parameters that have to be considered during extractionZipException - when an issue occurs during extractionpublic void extractFile(String fileName, String destinationPath) throws ZipException
ZipException.Type#FILE_NOT_FOUND if file header could not be found for the given file name.
Throws an exception if the destination path is invalid.fileName - name of the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractedZipException - when an issue occurs during extractionpublic void extractFile(String fileName, String destinationPath, UnzipParameters unzipParameters) throws ZipException
ZipException.Type#FILE_NOT_FOUND if file header could not be found for the given file name.
Throws an exception if the destination path is invalid.fileName - name of the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractedunzipParameters - any parameters that have to be considered during extractionZipException - when an issue occurs during extractionpublic void extractFile(String fileName, String destinationPath, String newFileName) throws ZipException
ZipException.Type#FILE_NOT_FOUND if file header could not be found for the given file name.
Throws an exception if the destination path is invalid.fileName - name of the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractednewFileName - if not null, this will be the name given to the file upon extractionZipException - when an issue occurs during extractionpublic void extractFile(FileHeader fileHeader, String destinationPath, String newFileName) throws ZipException
fileHeader - file header corresponding to the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractednewFileName - if not null, this will be the name given to the file upon extractionZipException - when an issue occurs during extractionpublic void extractFile(String fileName, String destinationPath, String newFileName, UnzipParameters unzipParameters) throws ZipException
ZipException.Type#FILE_NOT_FOUND if file header could not be found for the
given file name.
Throws an exception if the destination path is invalid.fileName - name of the entry which has to be extracteddestinationPath - path to which the entries of the zip are to be extractednewFileName - if not null, this will be the name given to the file upon extractionunzipParameters - any parameters that have to be considered during extractionZipException - when an issue occurs during extractionpublic List<FileHeader> getFileHeaders() throws ZipException
ZipExceptionpublic FileHeader getFileHeader(String fileName) throws ZipException
fileName - ZipExceptionpublic boolean isEncrypted()
throws ZipException
ZipExceptionpublic boolean isSplitArchive()
throws ZipException
ZipExceptionpublic void removeFile(FileHeader fileHeader) throws ZipException
fileHeader - ZipExceptionpublic void removeFile(String fileName) throws ZipException
fileName - ZipExceptionpublic void removeFiles(List<String> fileNames) throws ZipException
fileNames - ZipExceptionpublic void renameFile(FileHeader fileHeader, String newFileName) throws ZipException
fileHeader - file header to be changednewFileName - the file name that has to be changed toZipException - if fileHeader is null or newFileName is null or empty or if the zip file is a split filepublic void renameFile(String fileNameToRename, String newFileName) throws ZipException
fileNameToRename - file name in the zip that has to be renamednewFileName - the file name that has to be changed toZipException - if fileNameToRename is empty or newFileName is empty or if the zip file is a split filepublic void renameFiles(Map<String,String> fileNamesMap) throws ZipException
fileNamesMap - map of file names that have to be changed with values in the map being the name to be changed toZipException - if map is null or if the zip file is a split filepublic void mergeSplitFiles(File outputZipFile) throws ZipException
outputZipFile - ZipExceptionpublic void setComment(String comment) throws ZipException
comment - ZipExceptionpublic String getComment() throws ZipException
ZipExceptionpublic ZipInputStream getInputStream(FileHeader fileHeader) throws IOException
fileHeader - ZipExceptionIOExceptionpublic boolean isValidZipFile()
public List<File> getSplitZipFiles() throws ZipException
ZipExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException - when the underlying input stream throws an exception when trying to close itpublic void setPassword(char[] password)
password - - char array of the password to be usedpublic int getBufferSize()
public void setBufferSize(int bufferSize)
bufferSize - size of the buffer that should be used when reading streamsIllegalArgumentException - if bufferSize is less than value configured in InternalZipConstants.MIN_BUFF_SIZEpublic ProgressMonitor getProgressMonitor()
public boolean isRunInThread()
public void setRunInThread(boolean runInThread)
public File getFile()
public Charset getCharset()
public void setCharset(Charset charset) throws IllegalArgumentException
charset - charset to use to encode file names and commentsIllegalArgumentException - if charset is nullpublic void setThreadFactory(ThreadFactory threadFactory)
public ExecutorService getExecutorService()
Copyright © 2021. All rights reserved.