public class ZipFile extends Object
Constructor and Description |
---|
ZipFile(File zipFile)
Creates a new Zip File Object with the input file.
|
ZipFile(File zipFile,
char[] password) |
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 |
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 |
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(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.
|
Charset |
getCharset() |
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 |
setCharset(Charset charset) |
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
- public ZipFile(File zipFile, char[] password)
public 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 splitZipException
public void createSplitZipFileFromFolder(File folderToAdd, ZipParameters parameters, boolean splitArchive, long splitLength) throws ZipException
folderToAdd
- parameters
- splitArchive
- splitLength
- ZipException
public void addFile(String fileToAdd) throws ZipException
fileToAdd
- - File with path to be added to the zip fileZipException
public 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 zipZipException
public void addFile(File fileToAdd) throws ZipException
fileToAdd
- - File to be added to the zip fileZipException
public void addFile(File fileToAdd, ZipParameters parameters) throws ZipException
fileToAdd
- - File to be added to the zip fileparameters
- - zip parameters for this fileZipException
public void addFiles(List<File> filesToAdd) throws ZipException
filesToAdd
- ZipException
public void addFiles(List<File> filesToAdd, ZipParameters parameters) throws ZipException
filesToAdd
- parameters
- ZipException
public void addFolder(File folderToAdd) throws ZipException
folderToAdd
- ZipException
public void addFolder(File folderToAdd, ZipParameters zipParameters) throws ZipException
folderToAdd
- zipParameters
- ZipException
public void addStream(InputStream inputStream, ZipParameters parameters) throws ZipException
inputStream
- parameters
- ZipException
public void extractAll(String destinationPath) throws ZipException
destinationPath
- ZipException
public void extractFile(FileHeader fileHeader, String destinationPath) throws ZipException
fileHeader
- destinationPath
- ZipException
public void extractFile(FileHeader fileHeader, String destinationPath, String newFileName) throws ZipException
fileHeader
- destinationPath
- newFileName
- ZipException
public 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
- destinationPath
- ZipException
public 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
- destinationPath
- newFileName
- ZipException
public List<FileHeader> getFileHeaders() throws ZipException
ZipException
public FileHeader getFileHeader(String fileName) throws ZipException
fileName
- ZipException
public boolean isEncrypted() throws ZipException
ZipException
public boolean isSplitArchive() throws ZipException
ZipException
public void removeFile(FileHeader fileHeader) throws ZipException
fileHeader
- ZipException
public void removeFile(String fileName) throws ZipException
fileName
- ZipException
public void removeFiles(List<String> fileNames) throws ZipException
fileNames
- ZipException
public 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
- ZipException
public void setComment(String comment) throws ZipException
comment
- ZipException
public String getComment() throws ZipException
ZipException
public ZipInputStream getInputStream(FileHeader fileHeader) throws IOException
fileHeader
- ZipException
IOException
public boolean isValidZipFile()
public List<File> getSplitZipFiles() throws ZipException
ZipException
public void setPassword(char[] password)
password
- - char array of the password to be usedpublic ProgressMonitor getProgressMonitor()
public boolean isRunInThread()
public void setRunInThread(boolean runInThread)
public File getFile()
public Charset getCharset()
public void setCharset(Charset charset) throws IllegalArgumentException
IllegalArgumentException
public void setThreadFactory(ThreadFactory threadFactory)
public ExecutorService getExecutorService()
Copyright © 2020. All rights reserved.