java.lang.Object
com.aoapps.lang.zip.ZipUtils
ZIP file utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
copyEntries
(File file, ZipOutputStream zipOut) Copies all non-directory entries.static void
copyEntries
(File file, ZipOutputStream zipOut, ZipEntryFilter filter) Copies all non-directory entries.static void
copyEntries
(ZipFile zipFile, ZipOutputStream zipOut) Copies all non-directory entries.static void
copyEntries
(ZipFile zipFile, ZipOutputStream zipOut, ZipEntryFilter filter) Copies all entries.static void
createZipFile
(File sourceDirectory, File zipFile) Recursively packages a directory into a file.static void
createZipFile
(File sourceDirectory, OutputStream out) Recursively packages a directory into an output stream.static void
createZipFile
(File sourceDirectory, ZipOutputStream zipOut) Recursively packages a directory into a ZIP output stream.static void
createZipFile
(File file, ZipOutputStream zipOut, String path) Recursively packages a directory into a ZIP output stream.getCreationTimeUtc
(ZipEntry entry) Gets the creation time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.getLastAccessTimeUtc
(ZipEntry entry) Gets the last access time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.getLastModifiedTimeUtc
(ZipEntry entry) Gets the last modified time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.getTimeUtc
(ZipEntry entry) Gets the time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.static long
getZipEntryTime
(ZipEntry entry) Deprecated.static void
mergeUnzip
(ZipEntryFilter filter, File destination, File... zipFiles) Combine contents of all ZIP files while unzipping, only allowing duplicates where the file contents are equal.static void
mergeUnzip
(File destination, File... zipFiles) Combine contents of all ZIP files while unzipping, only allowing duplicates where the file contents are equal.static void
setCreationTimeUtc
(ZipEntry entry, long creationTime) Sets the creation time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.static void
setLastAccessTimeUtc
(ZipEntry entry, long lastAccessTime) Sets the last access time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.static void
setLastModifiedTimeUtc
(ZipEntry entry, long lastModifiedTime) Sets the last modified time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.static void
setTimeUtc
(ZipEntry entry, long time) Sets the time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.static void
setZipEntryTime
(ZipEntry entry, long time) Deprecated.Please usesetTimeUtc(java.util.zip.ZipEntry, long)
instead.static void
Unzips the provided file to the given destination directory.static void
unzip
(File sourceFile, String sourcePrefix, File destination, ZipEntryFilter filter) Unzips the provided file to the given destination directory.
-
Method Details
-
getTimeUtc
Gets the time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.- Returns:
- the time assuming UTC zone or
null
if not specified. - Throws:
ZipException
- See Also:
-
setTimeUtc
Sets the time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones. The actual time stored may be rounded to the nearest two-second interval.- Throws:
ZipException
- See Also:
-
getZipEntryTime
Deprecated.Please usegetTimeUtc(java.util.zip.ZipEntry)
instead.Gets the time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.- Returns:
- the time assuming UTC zone or
-1
if not specified. - See Also:
-
setZipEntryTime
Deprecated.Please usesetTimeUtc(java.util.zip.ZipEntry, long)
instead.Sets the time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones. The actual time stored may be rounded to the nearest two-second interval.- See Also:
-
getCreationTimeUtc
Gets the creation time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.- Returns:
- the creation time assuming UTC zone or
null
if not specified. - See Also:
-
setCreationTimeUtc
Sets the creation time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.- See Also:
-
getLastAccessTimeUtc
Gets the last access time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.- Returns:
- the last access time assuming UTC zone or
null
if not specified. - See Also:
-
setLastAccessTimeUtc
Sets the last access time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.- See Also:
-
getLastModifiedTimeUtc
Gets the last modified time for a ZipEntry, converting from UTC as stored in the ZIP entry to make times correct between time zones.- Returns:
- the last modified time assuming UTC zone or
null
if not specified. - See Also:
-
setLastModifiedTimeUtc
Sets the last modified time for a ZipEntry, converting to UTC while storing to the ZIP entry to make times correct between time zones.- See Also:
-
createZipFile
Recursively packages a directory into a file.- Throws:
IOException
-
createZipFile
Recursively packages a directory into an output stream.- Throws:
IOException
-
createZipFile
Recursively packages a directory into a ZIP output stream.- Throws:
IOException
-
createZipFile
Recursively packages a directory into a ZIP output stream.- Throws:
IOException
-
unzip
Unzips the provided file to the given destination directory.- Throws:
IOException
-
unzip
public static void unzip(File sourceFile, String sourcePrefix, File destination, ZipEntryFilter filter) throws IOException Unzips the provided file to the given destination directory.- Parameters:
sourceFile
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
mergeUnzip
Combine contents of all ZIP files while unzipping, only allowing duplicates where the file contents are equal. When duplicates are found, uses the most recent modification time.- Parameters:
zipFiles
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
mergeUnzip
public static void mergeUnzip(ZipEntryFilter filter, File destination, File... zipFiles) throws IOException Combine contents of all ZIP files while unzipping, only allowing duplicates where the file contents are equal. When duplicates are found, uses the most recent modification time.- Parameters:
zipFiles
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
copyEntries
Copies all non-directory entries.- Parameters:
file
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
copyEntries
public static void copyEntries(File file, ZipOutputStream zipOut, ZipEntryFilter filter) throws IOException Copies all non-directory entries.- Parameters:
file
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
copyEntries
Copies all non-directory entries.- Parameters:
zipFile
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
copyEntries
public static void copyEntries(ZipFile zipFile, ZipOutputStream zipOut, ZipEntryFilter filter) throws IOException Copies all entries.- Parameters:
zipFile
- Please take caution when extracting untrusted ZIP files. This method does nothing to protect against ZIP bombs. Please see Expanding archive files without controlling resource consumption is security-sensitive for details.- Throws:
IOException
-
getTimeUtc(java.util.zip.ZipEntry)
instead.