Package jodd.io
Class ZipUtil
- java.lang.Object
-
- jodd.io.ZipUtil
-
public class ZipUtil extends java.lang.ObjectPerforms zip/gzip/zlib operations on files and directories. These are just tools over existingjava.util.zipclasses, 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
-
-
Constructor Summary
Constructors Constructor Description ZipUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddFolderToZip(java.util.zip.ZipOutputStream zos, java.lang.String path, java.lang.String comment)static voidaddToZip(java.util.zip.ZipOutputStream zos, byte[] content, java.lang.String path, java.lang.String comment)Adds byte content into the zip as a file.static voidaddToZip(java.util.zip.ZipOutputStream zos, java.io.File file, java.lang.String path, java.lang.String comment, boolean recursive)Adds single entry to ZIP output stream.static voidclose(java.util.zip.ZipFile zipFile)Closes zip file safely.static java.io.Filegzip(java.io.File file)Compresses a file into gzip archive.static java.io.Filegzip(java.lang.String fileName)Compresses a file into gzip archive.static java.util.List<java.lang.String>listZip(java.io.File zipFile)Lists zip content.static java.io.Fileungzip(java.io.File file)Decompress gzip archive.static java.io.Fileungzip(java.lang.String file)Decompress gzip archive.static voidunzip(java.io.File zipFile, java.io.File destDir, java.lang.String... patterns)Extracts zip file to the target directory.static voidunzip(java.lang.String zipFile, java.lang.String destDir, java.lang.String... patterns)Extracts zip file content to the target directory.static java.io.Filezip(java.io.File file)Zips a file or a folder.static java.io.Filezip(java.lang.String file)Zips a file or a folder.static java.io.Filezlib(java.io.File file)Compresses a file into zlib archive.static java.io.Filezlib(java.lang.String file)Compresses a file into zlib archive.
-
-
-
Field Detail
-
ZIP_EXT
public static final java.lang.String ZIP_EXT
- See Also:
- Constant Field Values
-
GZIP_EXT
public static final java.lang.String GZIP_EXT
- See Also:
- Constant Field Values
-
ZLIB_EXT
public static final java.lang.String ZLIB_EXT
- See Also:
- Constant Field Values
-
-
Method Detail
-
zlib
public static java.io.File zlib(java.lang.String file) throws java.io.IOExceptionCompresses a file into zlib archive.- Throws:
java.io.IOException
-
zlib
public static java.io.File zlib(java.io.File file) throws java.io.IOExceptionCompresses a file into zlib archive.- Throws:
java.io.IOException
-
gzip
public static java.io.File gzip(java.lang.String fileName) throws java.io.IOExceptionCompresses a file into gzip archive.- Throws:
java.io.IOException
-
gzip
public static java.io.File gzip(java.io.File file) throws java.io.IOExceptionCompresses a file into gzip archive.- Throws:
java.io.IOException
-
ungzip
public static java.io.File ungzip(java.lang.String file) throws java.io.IOExceptionDecompress gzip archive.- Throws:
java.io.IOException
-
ungzip
public static java.io.File ungzip(java.io.File file) throws java.io.IOExceptionDecompress gzip archive.- Throws:
java.io.IOException
-
zip
public static java.io.File zip(java.lang.String file) throws java.io.IOExceptionZips a file or a folder.- Throws:
java.io.IOException- See Also:
zip(java.io.File)
-
zip
public static java.io.File zip(java.io.File file) throws java.io.IOExceptionZips a file or a folder. If adding a folder, all its content will be added.- Throws:
java.io.IOException
-
listZip
public static java.util.List<java.lang.String> listZip(java.io.File zipFile) throws java.io.IOExceptionLists zip content.- Throws:
java.io.IOException
-
unzip
public static void unzip(java.lang.String zipFile, java.lang.String destDir, java.lang.String... patterns) throws java.io.IOExceptionExtracts zip file content to the target directory.- Throws:
java.io.IOException- See Also:
unzip(java.io.File, java.io.File, String...)
-
unzip
public static void unzip(java.io.File zipFile, java.io.File destDir, java.lang.String... patterns) throws java.io.IOExceptionExtracts 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:
java.io.IOException
-
addToZip
public static void addToZip(java.util.zip.ZipOutputStream zos, java.io.File file, java.lang.String path, java.lang.String comment, boolean recursive) throws java.io.IOExceptionAdds 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:
java.io.IOException
-
addToZip
public static void addToZip(java.util.zip.ZipOutputStream zos, byte[] content, java.lang.String path, java.lang.String comment) throws java.io.IOExceptionAdds byte content into the zip as a file.- Throws:
java.io.IOException
-
addFolderToZip
public static void addFolderToZip(java.util.zip.ZipOutputStream zos, java.lang.String path, java.lang.String comment) throws java.io.IOException- Throws:
java.io.IOException
-
close
public static void close(java.util.zip.ZipFile zipFile)
Closes zip file safely.
-
-