|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.zeroturnaround.zip.ZipUtil
public final class ZipUtil
ZIP file manipulation utilities.
containsEntry(File, String),
unpackEntry(File, String),
unpack(File, File),
pack(File, File)| Method Summary | |
|---|---|
static void |
addEntries(File zip,
ZipEntrySource[] entries,
File destZip)
Copies an existing ZIP file and appends it with new entries. |
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,
File file,
File destZip)
Copies an existing ZIP file and appends it with one new entry. |
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,
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 void |
explode(File zip)
Unpacks a ZIP file to its own location. |
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,
ZipInfoCallback action)
Scans the given ZIP file and executes the given action for each entry. |
static void |
iterate(InputStream is,
ZipEntryCallback action)
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 rootDir,
File zip,
NameMapper mapper)
Compresses the given directory and all its sub-directories into a ZIP file. |
static void |
pack(ZipEntrySource[] entries,
File zip)
Compresses the given entries into a new ZIP file. |
static byte[] |
packEntry(File file)
Compresses the given file into a ZIP file with single entry. |
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,
File destZip)
Copies an existing ZIP file and 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,
File destZip)
Copies an existing ZIP file and replaces a given entry in it. |
static void |
unexplode(File dir)
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,
NameMapper mapper)
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,
NameMapper mapper)
Unpacks a ZIP stream to the given directory. |
static byte[] |
unpackEntry(File zip,
String name)
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static boolean containsEntry(File zip,
String name)
zip - ZIP file.name - entry name.
true if the ZIP file contains 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 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 void iterate(File zip,
ZipEntryCallback action)
For each entry the corresponding input stream is also passed to the action.
zip - input ZIP file.action - action to be called for each entry.ZipEntryCallback,
iterate(File, ZipInfoCallback)
public static void iterate(File zip,
ZipInfoCallback action)
Only the meta-data without the actual data is read.
zip - input ZIP file.action - action to be called for each entry.ZipInfoCallback,
iterate(File, ZipEntryCallback)
public static void iterate(InputStream is,
ZipEntryCallback action)
For each entry the corresponding input stream is also passed to the action.
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 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,
NameMapper mapper)
The output directory must not be a file.
zip - input ZIP file.outputDir - output directory (created automatically if not found).
public static void unpack(InputStream is,
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(InputStream is,
File outputDir,
NameMapper mapper)
The output directory must not be a file.
zip - input ZIP file.outputDir - output directory (created automatically if not found).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.
File - root directory.zip - ZIP file that will be created or overwritten.
public static void pack(File rootDir,
File zip,
NameMapper mapper)
The ZIP file must not be a directory and its parent directory must exist.
File - root directory.zip - ZIP file that will be created or overwritten.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 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,
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,
ZipEntrySource entry,
File destZip)
zip - an existing ZIP file (only read).entry - new ZIP entry appended.destZip - new ZIP file created.
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 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,
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,
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 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 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 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 void closeQuietly(ZipFile zf)
zf - ZIP file to be closed.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||