Class ZipUtil
java.lang.Object
jodd.io.ZipUtil
Performs zip/gzip/zlib operations on files and directories.
These are just tools over existing
java.util.zip classes,
meaning that existing behavior and bugs are persisted.
Most common issue is not being able to use UTF8 in file names,
because implementation uses old ZIP format that supports only
IBM Code Page 437. This bug was resolved in JDK7:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4244499-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFolderToZip(ZipOutputStream zos, String path, String comment) static voidaddToZip(ZipOutputStream zos, byte[] content, String path, String comment) Adds byte content into the zip as a file.static voidaddToZip(ZipOutputStream zos, File file, String path, String comment, boolean recursive) Adds single entry to ZIP output stream.static voidCloses zip file safely.static FileCompresses a file into gzip archive.static FileCompresses a file into gzip archive.Lists zip content.static FileDecompress gzip archive.static FileDecompress gzip archive.static voidExtracts zip file to the target directory.static voidExtracts zip file content to the target directory.static FileZips a file or a folder.static FileZips a file or a folder.static FileCompresses a file into zlib archive.static FileCompresses a file into zlib archive.
-
Field Details
-
ZIP_EXT
- See Also:
-
GZIP_EXT
- See Also:
-
ZLIB_EXT
- See Also:
-
-
Constructor Details
-
ZipUtil
public ZipUtil()
-
-
Method Details
-
zlib
Compresses a file into zlib archive.- Throws:
IOException
-
zlib
Compresses a file into zlib archive.- Throws:
IOException
-
gzip
Compresses a file into gzip archive.- Throws:
IOException
-
gzip
Compresses a file into gzip archive.- Throws:
IOException
-
ungzip
Decompress gzip archive.- Throws:
IOException
-
ungzip
Decompress gzip archive.- Throws:
IOException
-
zip
Zips a file or a folder.- Throws:
IOException- See Also:
-
zip
Zips a file or a folder. If adding a folder, all its content will be added.- Throws:
IOException
-
listZip
Lists zip content.- Throws:
IOException
-
unzip
Extracts zip file content to the target directory.- Throws:
IOException- See Also:
-
unzip
Extracts zip file to the target directory. If patterns are provided only matched paths are extracted.- Parameters:
zipFile- zip filedestDir- destination directorypatterns- optional wildcard patterns of files to extract, may benull- Throws:
IOException
-
addToZip
public static void addToZip(ZipOutputStream zos, File file, String path, String comment, boolean recursive) throws IOException Adds single entry to ZIP output stream.- Parameters:
zos- zip output streamfile- file or folder to addpath- relative path of file entry; ifnullfiles name will be used insteadcomment- optional commentrecursive- when set totruecontent of added folders will be added, too- Throws:
IOException
-
addToZip
public static void addToZip(ZipOutputStream zos, byte[] content, String path, String comment) throws IOException Adds byte content into the zip as a file.- Throws:
IOException
-
addFolderToZip
public static void addFolderToZip(ZipOutputStream zos, String path, String comment) throws IOException - Throws:
IOException
-
close
Closes zip file safely.
-