public final class ZipUtil extends Object
containsEntry(File, String)
,
unpackEntry(File, String)
,
unpack(File, File)
,
pack(File, File)
Modifier and Type | Class and Description |
---|---|
static class |
ZipUtil.BackslashUnpacker
Unpacks each ZIP entries.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_COMPRESSION_LEVEL
Default compression level
|
Modifier and Type | Method and Description |
---|---|
static void |
addEntries(File zip,
ZipEntrySource[] entries)
Changes a zip file it with with new entries.
|
static void |
addEntries(File zip,
ZipEntrySource[] entries,
File destZip)
Copies an existing ZIP file and appends it with new entries.
|
static void |
addEntries(File zip,
ZipEntrySource[] entries,
OutputStream destOut)
Copies an existing ZIP file and appends it with new entries.
|
static void |
addEntries(InputStream is,
ZipEntrySource[] entries,
OutputStream destOut)
Copies an existing ZIP file and appends it with new entries.
|
static void |
addEntry(File zip,
String path,
byte[] bytes)
Changes a zip file, adds one new entry in-place.
|
static void |
addEntry(File zip,
String path,
byte[] bytes,
File destZip)
Copies an existing ZIP file and appends it with one new entry.
|
static void |
addEntry(File zip,
String path,
byte[] bytes,
File destZip,
int compressionMethod)
Copies an existing ZIP file and appends it with one new entry.
|
static void |
addEntry(File zip,
String path,
byte[] bytes,
int compressionMethod)
Changes a zip file, adds one new entry in-place.
|
static void |
addEntry(File zip,
String path,
File file)
Changes a zip file, adds one new entry in-place.
|
static void |
addEntry(File zip,
String path,
File file,
File destZip)
Copies an existing ZIP file and appends it with one new entry.
|
static void |
addEntry(File zip,
ZipEntrySource entry)
Changes a zip file, adds one new entry in-place.
|
static void |
addEntry(File zip,
ZipEntrySource entry,
File destZip)
Copies an existing ZIP file and appends it with one new entry.
|
static void |
addOrReplaceEntries(File zip,
ZipEntrySource[] entries)
Changes a ZIP file: adds/replaces the given entries in it.
|
static void |
addOrReplaceEntries(File zip,
ZipEntrySource[] entries,
File destZip)
Copies an existing ZIP file and adds/replaces the given entries in it.
|
static boolean |
archiveEquals(File f1,
File f2)
Compares two ZIP files and returns
true if they contain same
entries. |
static void |
closeQuietly(ZipFile zf)
Closes the ZIP file while ignoring any errors.
|
static boolean |
containsAnyEntry(File zip,
String[] names)
Checks if the ZIP file contains any of the given entries.
|
static boolean |
containsEntry(File zip,
String name)
Checks if the ZIP file contains the given entry.
|
static boolean |
entryEquals(File f1,
File f2,
String path)
Compares same entry in two ZIP files (byte-by-byte).
|
static boolean |
entryEquals(File f1,
File f2,
String path1,
String path2)
Compares two ZIP entries (byte-by-byte).
|
static boolean |
entryEquals(ZipFile zf1,
ZipFile zf2,
String path1,
String path2)
Compares two ZIP entries (byte-by-byte).
|
static void |
explode(File zip)
Unpacks a ZIP file to its own location.
|
static int |
getCompressionLevelOfEntry(File zip,
String name)
Deprecated.
The compression level cannot be retrieved. This method exists only to ensure backwards compatibility with ZipUtil version 1.9, which returned the compression
method, not the level.
|
static int |
getCompressionMethodOfEntry(File zip,
String name)
Returns the compression method of a given entry of the ZIP file.
|
static boolean |
handle(File zip,
String name,
ZipEntryCallback action)
Reads the given ZIP file and executes the given action for a single entry.
|
static boolean |
handle(InputStream is,
String name,
ZipEntryCallback action)
Reads the given ZIP stream and executes the given action for a single
entry.
|
static void |
iterate(File zip,
String[] entryNames,
ZipEntryCallback action)
Reads the given ZIP file and executes the given action for each given entry.
|
static void |
iterate(File zip,
String[] entryNames,
ZipEntryCallback action,
Charset charset)
Reads the given ZIP file and executes the given action for each given entry.
|
static void |
iterate(File zip,
String[] entryNames,
ZipInfoCallback action)
Scans the given ZIP file and executes the given action for each given entry.
|
static void |
iterate(File zip,
ZipEntryCallback action)
Reads the given ZIP file and executes the given action for each entry.
|
static void |
iterate(File zip,
ZipEntryCallback action,
Charset charset)
Reads the given ZIP file and executes the given action for each entry.
|
static void |
iterate(File zip,
ZipInfoCallback action)
Scans the given ZIP file and executes the given action for each entry.
|
static void |
iterate(InputStream is,
String[] entryNames,
ZipEntryCallback action)
See @link{
iterate(InputStream, ZipEntryCallback, Charset) . |
static void |
iterate(InputStream is,
String[] entryNames,
ZipEntryCallback action,
Charset charset)
Reads the given ZIP stream and executes the given action for each given entry.
|
static void |
iterate(InputStream is,
ZipEntryCallback action)
|
static void |
iterate(InputStream is,
ZipEntryCallback action,
Charset charset)
Reads the given ZIP stream and executes the given action for each entry.
|
static void |
pack(File rootDir,
File zip)
Compresses the given directory and all its sub-directories into a ZIP file.
|
static void |
pack(File sourceDir,
File targetZipFile,
boolean preserveRoot)
Compresses the given directory and all its sub-directories into a ZIP file.
|
static void |
pack(File rootDir,
File zip,
int compressionLevel)
Compresses the given directory and all its sub-directories into a ZIP file.
|
static void |
pack(File sourceDir,
File targetZip,
NameMapper mapper)
Compresses the given directory and all its sub-directories into a ZIP file.
|
static void |
pack(File sourceDir,
File targetZip,
NameMapper mapper,
int compressionLevel)
Compresses the given directory and all its sub-directories into a ZIP file.
|
static void |
pack(File sourceDir,
OutputStream os)
Compresses the given directory and all of its sub-directories into the passed in
stream.
|
static void |
pack(File sourceDir,
OutputStream os,
int compressionLevel)
Compresses the given directory and all of its sub-directories into the passed in
stream.
|
static void |
pack(File sourceDir,
OutputStream os,
NameMapper mapper)
Compresses the given directory and all of its sub-directories into the passed in
stream.
|
static void |
pack(File sourceDir,
OutputStream os,
NameMapper mapper,
int compressionLevel)
Compresses the given directory and all of its sub-directories into the passed in
stream.
|
static void |
pack(ZipEntrySource[] entries,
File zip)
Compresses the given entries into a new ZIP file.
|
static void |
pack(ZipEntrySource[] entries,
OutputStream os)
Compresses the given entries into an output stream.
|
static void |
packEntries(File[] filesToPack,
File destZipFile)
Compresses the given files into a ZIP file.
|
static void |
packEntries(File[] filesToPack,
File destZipFile,
int compressionLevel)
Compresses the given files into a ZIP file.
|
static void |
packEntries(File[] filesToPack,
File destZipFile,
NameMapper mapper)
Compresses the given files into a ZIP file.
|
static void |
packEntries(File[] filesToPack,
File destZipFile,
NameMapper mapper,
int compressionLevel)
Compresses the given files into a ZIP file.
|
static byte[] |
packEntry(File file)
Compresses the given file into a ZIP file with single entry.
|
static void |
packEntry(File fileToPack,
File destZipFile)
Compresses the given file into a ZIP file.
|
static void |
packEntry(File fileToPack,
File destZipFile,
NameMapper mapper)
Compresses the given file into a ZIP file.
|
static void |
packEntry(File fileToPack,
File destZipFile,
String fileName)
Compresses the given file into a ZIP file.
|
static void |
removeEntries(File zip,
String[] paths)
Changes an existing ZIP file: removes entries with given paths.
|
static void |
removeEntries(File zip,
String[] paths,
File destZip)
Copies an existing ZIP file and removes entries with given paths.
|
static void |
removeEntry(File zip,
String path)
Changes an existing ZIP file: removes entry with a given path.
|
static void |
removeEntry(File zip,
String path,
File destZip)
Copies an existing ZIP file and removes entry with a given path.
|
static void |
repack(File srcZip,
File dstZip,
int compressionLevel)
Repacks a provided ZIP file into a new ZIP with a given compression level.
|
static void |
repack(File zip,
int compressionLevel)
Repacks a provided ZIP file and replaces old file with the new one.
|
static void |
repack(InputStream is,
File dstZip,
int compressionLevel)
Repacks a provided ZIP input stream into a ZIP file with a given compression level.
|
static boolean |
replaceEntries(File zip,
ZipEntrySource[] entries)
Changes an existing ZIP file: replaces a given entry in it.
|
static boolean |
replaceEntries(File zip,
ZipEntrySource[] entries,
File destZip)
Copies an existing ZIP file and replaces the given entries in it.
|
static boolean |
replaceEntry(File zip,
String path,
byte[] bytes)
Changes an existing ZIP file: replaces a given entry in it.
|
static boolean |
replaceEntry(File zip,
String path,
byte[] bytes,
File destZip)
Copies an existing ZIP file and replaces a given entry in it.
|
static boolean |
replaceEntry(File zip,
String path,
byte[] bytes,
int compressionMethod)
Changes an existing ZIP file: replaces a given entry in it.
|
static boolean |
replaceEntry(File zip,
String path,
File file)
Changes an existing ZIP file: replaces a given entry in it.
|
static boolean |
replaceEntry(File zip,
String path,
File file,
File destZip)
Copies an existing ZIP file and replaces a given entry in it.
|
static boolean |
replaceEntry(File zip,
ZipEntrySource entry)
Changes an existing ZIP file: replaces a given entry in it.
|
static boolean |
replaceEntry(File zip,
ZipEntrySource entry,
File destZip)
Copies an existing ZIP file and replaces a given entry in it.
|
static boolean |
transformEntries(File zip,
ZipEntryTransformerEntry[] entries)
Changes an existing ZIP file: transforms a given entries in it.
|
static boolean |
transformEntries(File zip,
ZipEntryTransformerEntry[] entries,
File destZip)
Copies an existing ZIP file and transforms the given entries in it.
|
static boolean |
transformEntries(InputStream is,
ZipEntryTransformerEntry[] entries,
OutputStream os)
Copies an existing ZIP file and transforms the given entries in it.
|
static boolean |
transformEntry(File zip,
String path,
ZipEntryTransformer transformer)
Changes an existing ZIP file: transforms a given entry in it.
|
static boolean |
transformEntry(File zip,
String path,
ZipEntryTransformer transformer,
File destZip)
Copies an existing ZIP file and transforms a given entry in it.
|
static boolean |
transformEntry(File zip,
ZipEntryTransformerEntry entry)
Changes an existing ZIP file: transforms a given entry in it.
|
static boolean |
transformEntry(File zip,
ZipEntryTransformerEntry entry,
File destZip)
Copies an existing ZIP file and transforms a given entry in it.
|
static boolean |
transformEntry(InputStream is,
String path,
ZipEntryTransformer transformer,
OutputStream os)
Copies an existing ZIP file and transforms a given entry in it.
|
static boolean |
transformEntry(InputStream is,
ZipEntryTransformerEntry entry,
OutputStream os)
Copies an existing ZIP file and transforms a given entry in it.
|
static void |
unexplode(File dir)
Compresses a given directory in its own location.
|
static void |
unexplode(File dir,
int compressionLevel)
Compresses a given directory in its own location.
|
static void |
unpack(File zip,
File outputDir)
Unpacks a ZIP file to the given directory.
|
static void |
unpack(File zip,
File outputDir,
Charset charset)
Unpacks a ZIP file to the given directory using a specific Charset
for the input file.
|
static void |
unpack(File zip,
File outputDir,
NameMapper mapper)
Unpacks a ZIP file to the given directory using a specific Charset
for the input file.
|
static void |
unpack(File zip,
File outputDir,
NameMapper mapper,
Charset charset)
Unpacks a ZIP file to the given directory.
|
static void |
unpack(InputStream is,
File outputDir)
Unpacks a ZIP stream to the given directory.
|
static void |
unpack(InputStream is,
File outputDir,
Charset charset)
Unpacks a ZIP stream to the given directory.
|
static void |
unpack(InputStream is,
File outputDir,
NameMapper mapper)
Unpacks a ZIP stream to the given directory.
|
static void |
unpack(InputStream is,
File outputDir,
NameMapper mapper,
Charset charset)
Unpacks a ZIP stream to the given directory.
|
static byte[] |
unpackEntry(File zip,
String name)
Unpacks a single entry from a ZIP file.
|
static byte[] |
unpackEntry(File zip,
String name,
Charset charset)
Unpacks a single entry from a ZIP file.
|
static boolean |
unpackEntry(File zip,
String name,
File file)
Unpacks a single file from a ZIP archive to a file.
|
static boolean |
unpackEntry(File zip,
String name,
File file,
Charset charset)
Unpacks a single file from a ZIP archive to a file.
|
static byte[] |
unpackEntry(InputStream is,
String name)
Unpacks a single entry from a ZIP stream.
|
static boolean |
unpackEntry(InputStream is,
String name,
File file)
Unpacks a single file from a ZIP stream to a file.
|
static byte[] |
unpackEntry(ZipFile zf,
String name)
Unpacks a single entry from a ZIP file.
|
static boolean |
unpackEntry(ZipFile zf,
String name,
File file)
Unpacks a single file from a ZIP archive to a file.
|
static void |
unwrap(File zip,
File outputDir)
Unwraps a ZIP file to the given directory shaving of root dir.
|
static void |
unwrap(File zip,
File outputDir,
NameMapper mapper)
Unwraps a ZIP file to the given directory shaving of root dir.
|
static void |
unwrap(InputStream is,
File outputDir)
Unwraps a ZIP file to the given directory shaving of root dir.
|
static void |
unwrap(InputStream is,
File outputDir,
NameMapper mapper)
Unwraps a ZIP file to the given directory shaving of root dir.
|
public static final int DEFAULT_COMPRESSION_LEVEL
public static boolean containsEntry(File zip, String name)
zip
- ZIP file.name
- entry name.true
if the ZIP file contains the given entry.@Deprecated public static int getCompressionLevelOfEntry(File zip, String name)
zip
- ZIP file.name
- entry name.ZipEntry.STORED
, ZipEntry.DEFLATED
or -1 if
the ZIP file does not contain the given entry.public static int getCompressionMethodOfEntry(File zip, String name)
zip
- ZIP file.name
- entry name.ZipEntry.STORED
, ZipEntry.DEFLATED
or -1 if
the ZIP file does not contain the given entry.public static boolean containsAnyEntry(File zip, String[] names)
zip
- ZIP file.names
- entry names.true
if the ZIP file contains any of the given
entries.public static byte[] unpackEntry(File zip, String name)
zip
- ZIP file.name
- entry name.null
if it was not found.public static byte[] unpackEntry(File zip, String name, Charset charset)
zip
- ZIP file.name
- entry name.charset
- charset to be used to process the zipnull
if it was not found.public static byte[] unpackEntry(ZipFile zf, String name)
zf
- ZIP file.name
- entry name.null
if it was not found.public static byte[] unpackEntry(InputStream is, String name)
is
- ZIP stream.name
- entry name.null
if it was not found.public static boolean unpackEntry(File zip, String name, File file)
zip
- ZIP file.name
- entry name.file
- target file to be created or overwritten.true
if the entry was found and unpacked,
false
if the entry was not found.public static boolean unpackEntry(File zip, String name, File file, Charset charset)
zip
- ZIP file.name
- entry name.file
- target file to be created or overwritten.charset
- charset to be used processing the ziptrue
if the entry was found and unpacked,
false
if the entry was not found.public static boolean unpackEntry(ZipFile zf, String name, File file)
zf
- ZIP file.name
- entry name.file
- target file to be created or overwritten.true
if the entry was found and unpacked,
false
if the entry was not found.public static boolean unpackEntry(InputStream is, String name, File file) throws IOException
is
- ZIP stream.name
- entry name.file
- target file to be created or overwritten.true
if the entry was found and unpacked,
false
if the entry was not found.IOException
- if file is not found or writing to it failspublic static void iterate(File zip, ZipEntryCallback action)
For each entry the corresponding input stream is also passed to the action. If you want to stop the loop then throw a ZipBreakException.
zip
- input ZIP file.action
- action to be called for each entry.ZipEntryCallback
,
iterate(File, ZipInfoCallback)
public static void iterate(File zip, ZipEntryCallback action, Charset charset)
For each entry the corresponding input stream is also passed to the action. If you want to stop the loop then throw a ZipBreakException.
zip
- input ZIP file.action
- action to be called for each entry.charset
- Charset used to processed the ZipFile withZipEntryCallback
,
iterate(File, ZipInfoCallback)
public static void iterate(File zip, String[] entryNames, ZipEntryCallback action)
For each given entry the corresponding input stream is also passed to the action. If you want to stop the loop then throw a ZipBreakException.
zip
- input ZIP file.entryNames
- names of entries to iterateaction
- action to be called for each entry.ZipEntryCallback
,
iterate(File, String[], ZipInfoCallback)
public static void iterate(File zip, String[] entryNames, ZipEntryCallback action, Charset charset)
For each given entry the corresponding input stream is also passed to the action. If you want to stop the loop then throw a ZipBreakException.
zip
- input ZIP file.entryNames
- names of entries to iterateaction
- action to be called for each entry.charset
- charset used to process the zip fileZipEntryCallback
,
iterate(File, String[], ZipInfoCallback)
public static void iterate(File zip, ZipInfoCallback action)
Only the meta-data without the actual data is read. If you want to stop the loop then throw a ZipBreakException.
zip
- input ZIP file.action
- action to be called for each entry.ZipInfoCallback
,
iterate(File, ZipEntryCallback)
public static void iterate(File zip, String[] entryNames, ZipInfoCallback action)
Only the meta-data without the actual data is read. If you want to stop the loop then throw a ZipBreakException.
zip
- input ZIP file.entryNames
- names of entries to iterateaction
- action to be called for each entry.ZipInfoCallback
,
iterate(File, String[], ZipEntryCallback)
public static void iterate(InputStream is, ZipEntryCallback action, Charset charset)
For each entry the corresponding input stream is also passed to the action. If you want to stop the loop then throw a ZipBreakException.
is
- input ZIP stream (it will not be closed automatically).action
- action to be called for each entry.charset
- charset to process entries inZipEntryCallback
,
iterate(File, ZipEntryCallback)
public static void iterate(InputStream is, ZipEntryCallback action)
iterate(InputStream, ZipEntryCallback, Charset)
. This method
is a shorthand for a version where no Charset is specified.is
- input ZIP stream (it will not be closed automatically).action
- action to be called for each entry.ZipEntryCallback
,
iterate(File, ZipEntryCallback)
public static void iterate(InputStream is, String[] entryNames, ZipEntryCallback action, Charset charset)
For each given entry the corresponding input stream is also passed to the action. If you want to stop the loop then throw a ZipBreakException.
is
- input ZIP stream (it will not be closed automatically).entryNames
- names of entries to iterateaction
- action to be called for each entry.charset
- charset to process entries inZipEntryCallback
,
iterate(File, String[], ZipEntryCallback)
public static void iterate(InputStream is, String[] entryNames, ZipEntryCallback action)
iterate(InputStream, ZipEntryCallback, Charset)
. It is a
shorthand where no Charset is specified.is
- input ZIP stream (it will not be closed automatically).entryNames
- names of entries to iterateaction
- action to be called for each entry.ZipEntryCallback
,
iterate(File, String[], ZipEntryCallback)
public static boolean handle(File zip, String name, ZipEntryCallback action)
zip
- input ZIP file.name
- entry name.action
- action to be called for this entry.true
if the entry was found, false
if the
entry was not found.ZipEntryCallback
public static boolean handle(InputStream is, String name, ZipEntryCallback action)
is
- input ZIP stream (it will not be closed automatically).name
- entry name.action
- action to be called for this entry.true
if the entry was found, false
if the
entry was not found.ZipEntryCallback
public static void unpack(File zip, File outputDir)
The output directory must not be a file.
zip
- input ZIP file.outputDir
- output directory (created automatically if not found).public static void unpack(File zip, File outputDir, Charset charset)
The output directory must not be a file.
zip
- input ZIP file.outputDir
- output directory (created automatically if not found).charset
- charset used to unpack the zip filepublic static void unpack(File zip, File outputDir, NameMapper mapper, Charset charset)
The output directory must not be a file.
zip
- input ZIP file.outputDir
- output directory (created automatically if not found).mapper
- call-back for renaming the entries.charset
- charset used to process the zip filepublic static void unpack(File zip, File outputDir, NameMapper mapper)
The output directory must not be a file.
zip
- input ZIP file.outputDir
- output directory (created automatically if not found).mapper
- call-back for renaming the entries.public static void unwrap(File zip, File outputDir)
The output directory must not be a file.
zip
- input ZIP file.outputDir
- output directory (created automatically if not found).public static void unwrap(File zip, File outputDir, NameMapper mapper)
The output directory must not be a file.
zip
- input ZIP file.outputDir
- output directory (created automatically if not found).mapper
- call-back for renaming the entries.public static void unpack(InputStream is, File outputDir)
The output directory must not be a file.
is
- inputstream for ZIP file.outputDir
- output directory (created automatically if not found).public static void unpack(InputStream is, File outputDir, Charset charset)
The output directory must not be a file.
is
- inputstream for ZIP file.outputDir
- output directory (created automatically if not found).charset
- charset used to process the zip streampublic static void unpack(InputStream is, File outputDir, NameMapper mapper)
The output directory must not be a file.
is
- inputstream for ZIP file.outputDir
- output directory (created automatically if not found).mapper
- call-back for renaming the entries.public static void unpack(InputStream is, File outputDir, NameMapper mapper, Charset charset)
The output directory must not be a file.
is
- inputstream for ZIP file.outputDir
- output directory (created automatically if not found).mapper
- call-back for renaming the entries.charset
- charset to use when unpacking the streampublic static void unwrap(InputStream is, File outputDir)
The output directory must not be a file.
is
- inputstream for ZIP file.outputDir
- output directory (created automatically if not found).public static void unwrap(InputStream is, File outputDir, NameMapper mapper)
The output directory must not be a file.
is
- inputstream for ZIP file.outputDir
- output directory (created automatically if not found).mapper
- call-back for renaming the entries.public static void explode(File zip)
The ZIP file will be first renamed (using a temporary name). After the extraction it will be deleted.
zip
- input ZIP file as well as the target directory.unpack(File, File)
public static byte[] packEntry(File file)
file
- file to be compressed.public static void pack(File rootDir, File zip)
The ZIP file must not be a directory and its parent directory must exist. Will not include the root directory name in the archive.
rootDir
- root directory.zip
- ZIP file that will be created or overwritten.public static void pack(File rootDir, File zip, int compressionLevel)
The ZIP file must not be a directory and its parent directory must exist. Will not include the root directory name in the archive.
rootDir
- root directory.zip
- ZIP file that will be created or overwritten.compressionLevel
- compression levelpublic static void pack(File sourceDir, File targetZipFile, boolean preserveRoot)
The ZIP file must not be a directory and its parent directory must exist. Will not include the root directory name in the archive.
sourceDir
- root directory.targetZipFile
- ZIP file that will be created or overwritten.preserveRoot
- true if the resulted archive should have the top directory entrypublic static void packEntry(File fileToPack, File destZipFile)
The ZIP file must not be a directory and its parent directory must exist.
fileToPack
- file that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.public static void packEntry(File fileToPack, File destZipFile, String fileName)
The ZIP file must not be a directory and its parent directory must exist.
fileToPack
- file that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.fileName
- the name for the file inside the archivepublic static void packEntry(File fileToPack, File destZipFile, NameMapper mapper)
The ZIP file must not be a directory and its parent directory must exist.
fileToPack
- file that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.mapper
- call-back for renaming the entries.public static void packEntries(File[] filesToPack, File destZipFile)
The ZIP file must not be a directory and its parent directory must exist.
filesToPack
- files that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.public static void packEntries(File[] filesToPack, File destZipFile, NameMapper mapper)
The ZIP file must not be a directory and its parent directory must exist.
filesToPack
- files that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.mapper
- call-back for renaming the entries.public static void packEntries(File[] filesToPack, File destZipFile, int compressionLevel)
The ZIP file must not be a directory and its parent directory must exist.
filesToPack
- files that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.compressionLevel
- ZIP file compression level (speed versus filesize), e.g. Deflater.NO_COMPRESSION
, Deflater.BEST_SPEED
, or
Deflater.BEST_COMPRESSION
public static void packEntries(File[] filesToPack, File destZipFile, NameMapper mapper, int compressionLevel)
The ZIP file must not be a directory and its parent directory must exist.
filesToPack
- files that needs to be zipped.destZipFile
- ZIP file that will be created or overwritten.mapper
- call-back for renaming the entries.compressionLevel
- ZIP file compression level (speed versus filesize), e.g. Deflater.NO_COMPRESSION
, Deflater.BEST_SPEED
, or
Deflater.BEST_COMPRESSION
public static void pack(File sourceDir, File targetZip, NameMapper mapper)
The ZIP file must not be a directory and its parent directory must exist.
sourceDir
- root directory.targetZip
- ZIP file that will be created or overwritten.mapper
- call-back for renaming the entries.public static void pack(File sourceDir, File targetZip, NameMapper mapper, int compressionLevel)
The ZIP file must not be a directory and its parent directory must exist.
sourceDir
- root directory.targetZip
- ZIP file that will be created or overwritten.mapper
- call-back for renaming the entries.compressionLevel
- compression levelpublic static void pack(File sourceDir, OutputStream os)
sourceDir
- root directory.os
- output stream (will be buffered in this method).public static void pack(File sourceDir, OutputStream os, int compressionLevel)
sourceDir
- root directory.os
- output stream (will be buffered in this method).compressionLevel
- compression levelpublic static void pack(File sourceDir, OutputStream os, NameMapper mapper)
sourceDir
- root directory.os
- output stream (will be buffered in this method).mapper
- call-back for renaming the entries.public static void pack(File sourceDir, OutputStream os, NameMapper mapper, int compressionLevel)
sourceDir
- root directory.os
- output stream (will be buffered in this method).mapper
- call-back for renaming the entries.compressionLevel
- compression levelpublic static void repack(File srcZip, File dstZip, int compressionLevel)
srcZip
- source ZIP file.dstZip
- destination ZIP file.compressionLevel
- compression level.public static void repack(InputStream is, File dstZip, int compressionLevel)
is
- ZIP input stream.dstZip
- destination ZIP file.compressionLevel
- compression level.public static void repack(File zip, int compressionLevel)
zip
- source ZIP file to be repacked and replaced.compressionLevel
- compression level.public static void unexplode(File dir)
A ZIP file will be first created with a temporary name. After the compressing the directory will be deleted and the ZIP file will be renamed as the original directory.
dir
- input directory as well as the target ZIP file.pack(File, File)
public static void unexplode(File dir, int compressionLevel)
A ZIP file will be first created with a temporary name. After the compressing the directory will be deleted and the ZIP file will be renamed as the original directory.
dir
- input directory as well as the target ZIP file.compressionLevel
- compression levelpack(File, File)
public static void pack(ZipEntrySource[] entries, OutputStream os)
entries
- ZIP entries added.os
- output stream for the new ZIP (does not have to be buffered)public static void pack(ZipEntrySource[] entries, File zip)
entries
- ZIP entries added.zip
- new ZIP file created.public static void addEntry(File zip, String path, File file, File destZip)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.file
- new entry to be added.destZip
- new ZIP file created.public static void addEntry(File zip, String path, File file)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.file
- new entry to be added.public static void addEntry(File zip, String path, byte[] bytes, File destZip)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).destZip
- new ZIP file created.public static void addEntry(File zip, String path, byte[] bytes, File destZip, int compressionMethod)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).destZip
- new ZIP file created.compressionMethod
- the new compression method (ZipEntry.STORED
or ZipEntry.DEFLATED
).public static void addEntry(File zip, String path, byte[] bytes)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).public static void addEntry(File zip, String path, byte[] bytes, int compressionMethod)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).compressionMethod
- the new compression method (ZipEntry.STORED
or ZipEntry.DEFLATED
).public static void addEntry(File zip, ZipEntrySource entry, File destZip)
zip
- an existing ZIP file (only read).entry
- new ZIP entry appended.destZip
- new ZIP file created.public static void addEntry(File zip, ZipEntrySource entry)
zip
- an existing ZIP file (only read).entry
- new ZIP entry appended.public static void addEntries(File zip, ZipEntrySource[] entries, File destZip)
zip
- an existing ZIP file (only read).entries
- new ZIP entries appended.destZip
- new ZIP file created.public static void addEntries(File zip, ZipEntrySource[] entries, OutputStream destOut)
zip
- an existing ZIP file (only read).entries
- new ZIP entries appended.destOut
- new ZIP destination output streampublic static void addEntries(InputStream is, ZipEntrySource[] entries, OutputStream destOut)
is
- an existing ZIP input stream.entries
- new ZIP entries appended.destOut
- new ZIP destination output streampublic static void addEntries(File zip, ZipEntrySource[] entries)
zip
- an existing ZIP file (only read).entries
- new ZIP entries appended.public static void removeEntry(File zip, String path, File destZip)
zip
- an existing ZIP file (only read)path
- path of the entry to removedestZip
- new ZIP file created.public static void removeEntry(File zip, String path)
zip
- an existing ZIP filepath
- path of the entry to removepublic static void removeEntries(File zip, String[] paths, File destZip)
zip
- an existing ZIP file (only read)paths
- paths of the entries to removedestZip
- new ZIP file created.public static void removeEntries(File zip, String[] paths)
zip
- an existing ZIP filepaths
- paths of the entries to removepublic static boolean replaceEntry(File zip, String path, File file, File destZip)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.file
- new entry.destZip
- new ZIP file created.true
if the entry was replaced.public static boolean replaceEntry(File zip, String path, File file)
zip
- an existing ZIP file.path
- new ZIP entry path.file
- new entry.true
if the entry was replaced.public static boolean replaceEntry(File zip, String path, byte[] bytes, File destZip)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).destZip
- new ZIP file created.true
if the entry was replaced.public static boolean replaceEntry(File zip, String path, byte[] bytes)
zip
- an existing ZIP file.path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).true
if the entry was replaced.public static boolean replaceEntry(File zip, String path, byte[] bytes, int compressionMethod)
zip
- an existing ZIP file.path
- new ZIP entry path.bytes
- new entry bytes (or null
if directory).compressionMethod
- the new compression method (ZipEntry.STORED
or ZipEntry.DEFLATED
).true
if the entry was replaced.public static boolean replaceEntry(File zip, ZipEntrySource entry, File destZip)
zip
- an existing ZIP file (only read).entry
- new ZIP entry.destZip
- new ZIP file created.true
if the entry was replaced.public static boolean replaceEntry(File zip, ZipEntrySource entry)
zip
- an existing ZIP file.entry
- new ZIP entry.true
if the entry was replaced.public static boolean replaceEntries(File zip, ZipEntrySource[] entries, File destZip)
zip
- an existing ZIP file (only read).entries
- new ZIP entries to be replaced with.destZip
- new ZIP file created.true
if at least one entry was replaced.public static boolean replaceEntries(File zip, ZipEntrySource[] entries)
zip
- an existing ZIP file.entries
- new ZIP entries to be replaced with.true
if at least one entry was replaced.public static void addOrReplaceEntries(File zip, ZipEntrySource[] entries, File destZip)
zip
- an existing ZIP file (only read).entries
- ZIP entries to be replaced or added.destZip
- new ZIP file created.public static void addOrReplaceEntries(File zip, ZipEntrySource[] entries)
zip
- an existing ZIP file (only read).entries
- ZIP entries to be replaced or added.public static boolean transformEntry(File zip, String path, ZipEntryTransformer transformer, File destZip)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.transformer
- transformer for the given ZIP entry.destZip
- new ZIP file created.true
if the entry was replaced.public static boolean transformEntry(File zip, String path, ZipEntryTransformer transformer)
zip
- an existing ZIP file (only read).path
- new ZIP entry path.transformer
- transformer for the given ZIP entry.true
if the entry was replaced.public static boolean transformEntry(File zip, ZipEntryTransformerEntry entry, File destZip)
zip
- an existing ZIP file (only read).entry
- transformer for a ZIP entry.destZip
- new ZIP file created.true
if the entry was replaced.public static boolean transformEntry(File zip, ZipEntryTransformerEntry entry)
zip
- an existing ZIP file (only read).entry
- transformer for a ZIP entry.true
if the entry was replaced.public static boolean transformEntries(File zip, ZipEntryTransformerEntry[] entries, File destZip)
zip
- an existing ZIP file (only read).entries
- ZIP entry transformers.destZip
- new ZIP file created.true
if at least one entry was replaced.public static boolean transformEntries(File zip, ZipEntryTransformerEntry[] entries)
zip
- an existing ZIP file (only read).entries
- ZIP entry transformers.true
if the entry was replaced.public static boolean transformEntry(InputStream is, String path, ZipEntryTransformer transformer, OutputStream os)
is
- a ZIP input stream.path
- new ZIP entry path.transformer
- transformer for the given ZIP entry.os
- a ZIP output stream.true
if the entry was replaced.public static boolean transformEntry(InputStream is, ZipEntryTransformerEntry entry, OutputStream os)
is
- a ZIP input stream.entry
- transformer for a ZIP entry.os
- a ZIP output stream.true
if the entry was replaced.public static boolean transformEntries(InputStream is, ZipEntryTransformerEntry[] entries, OutputStream os)
is
- a ZIP input stream.entries
- ZIP entry transformers.os
- a ZIP output stream.true
if at least one entry was replaced.public static boolean archiveEquals(File f1, File f2)
true
if they contain same
entries.
First the two files are compared byte-by-byte. If a difference is found the corresponding entries of both ZIP files are compared. Thus if same contents is packed differently the two archives may still be the same.
Two archives are considered the same if
f1
- first ZIP file.f2
- second ZIP file.true
if the two ZIP files contain same entries,
false
if a difference was found or an error occurred
during the comparison.public static boolean entryEquals(File f1, File f2, String path)
f1
- first ZIP file.f2
- second ZIP file.path
- name of the entry.true
if the contents of the entry was same in both ZIP
files.public static boolean entryEquals(File f1, File f2, String path1, String path2)
f1
- first ZIP file.f2
- second ZIP file.path1
- name of the first entry.path2
- name of the second entry.true
if the contents of the entries were same.public static boolean entryEquals(ZipFile zf1, ZipFile zf2, String path1, String path2)
zf1
- first ZIP file.zf2
- second ZIP file.path1
- name of the first entry.path2
- name of the second entry.true
if the contents of the entries were same.public static void closeQuietly(ZipFile zf)
zf
- ZIP file to be closed.Copyright © 2017 ZeroTurnaround. All rights reserved.