- java.lang.Object
-
- com.aoapps.lang.zip.ZipUtils
-
public final class ZipUtils extends Object
ZIP file utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyEntries(File file, ZipOutputStream zipOut)Copies all non-directory entries.static voidcopyEntries(File file, ZipOutputStream zipOut, ZipEntryFilter filter)Copies all non-directory entries.static voidcopyEntries(ZipFile zipFile, ZipOutputStream zipOut)Copies all non-directory entries.static voidcopyEntries(ZipFile zipFile, ZipOutputStream zipOut, ZipEntryFilter filter)Copies all entries.static voidcreateZipFile(File sourceDirectory, File zipFile)Recursively packages a directory into a file.static voidcreateZipFile(File sourceDirectory, OutputStream out)Recursively packages a directory into an output stream.static voidcreateZipFile(File sourceDirectory, ZipOutputStream zipOut)Recursively packages a directory into a ZIP output stream.static voidcreateZipFile(File file, ZipOutputStream zipOut, String path)Recursively packages a directory into a ZIP output stream.static longgetZipEntryTime(ZipEntry entry)Gets the time for a ZipEntry, converting from GMT as stored in the ZIP entry to make times correct between time zones.static voidmergeUnzip(ZipEntryFilter filter, File destination, File... zipFiles)Combine contents of all ZIP files while unzipping, only allowing duplicates where the file contents are equal.static voidmergeUnzip(File destination, File... zipFiles)Combine contents of all ZIP files while unzipping, only allowing duplicates where the file contents are equal.static voidsetZipEntryTime(ZipEntry entry, long time)Sets the time for a ZipEntry, converting to GMT while storing to the ZIP entry to make times correct between time zones.static voidunzip(File sourceFile, File destination)Unzips the provided file to the given destination directory.static voidunzip(File sourceFile, String sourcePrefix, File destination, ZipEntryFilter filter)Unzips the provided file to the given destination directory.
-
-
-
Method Detail
-
getZipEntryTime
public static long getZipEntryTime(ZipEntry entry)
Gets the time for a ZipEntry, converting from GMT as stored in the ZIP entry to make times correct between time zones.- Returns:
- the time assuming GMT zone or
-1if not specified. - See Also:
setZipEntryTime(ZipEntry, long)
-
setZipEntryTime
public static void setZipEntryTime(ZipEntry entry, long time)
Sets the time for a ZipEntry, converting to GMT 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:
getZipEntryTime(ZipEntry)
-
createZipFile
public static void createZipFile(File sourceDirectory, File zipFile) throws IOException
Recursively packages a directory into a file.- Throws:
IOException
-
createZipFile
public static void createZipFile(File sourceDirectory, OutputStream out) throws IOException
Recursively packages a directory into an output stream.- Throws:
IOException
-
createZipFile
public static void createZipFile(File sourceDirectory, ZipOutputStream zipOut) throws IOException
Recursively packages a directory into a ZIP output stream.- Throws:
IOException
-
createZipFile
public static void createZipFile(File file, ZipOutputStream zipOut, String path) throws IOException
Recursively packages a directory into a ZIP output stream.- Throws:
IOException
-
unzip
public static void unzip(File sourceFile, File destination) throws IOException
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
public static void mergeUnzip(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
-
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
public static void copyEntries(File file, ZipOutputStream zipOut) 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
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
public static void copyEntries(ZipFile zipFile, ZipOutputStream zipOut) throws IOException
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
-
-