public class ZipUtil
extends java.lang.Object
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=4244499Modifier and Type | Field and Description |
---|---|
static java.lang.String |
GZIP_EXT |
static java.lang.String |
ZIP_EXT |
static java.lang.String |
ZLIB_EXT |
Constructor and Description |
---|
ZipUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
addFolderToZip(java.util.zip.ZipOutputStream zos,
java.lang.String path,
java.lang.String comment) |
static void |
addToZip(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 void |
addToZip(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 void |
close(java.util.zip.ZipFile zipFile)
Closes zip file safely.
|
static java.io.File |
gzip(java.io.File file)
Compresses a file into gzip archive.
|
static java.io.File |
gzip(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.File |
ungzip(java.io.File file)
Decompress gzip archive.
|
static java.io.File |
ungzip(java.lang.String file)
Decompress gzip archive.
|
static void |
unzip(java.io.File zipFile,
java.io.File destDir,
java.lang.String... patterns)
Extracts zip file to the target directory.
|
static void |
unzip(java.lang.String zipFile,
java.lang.String destDir,
java.lang.String... patterns)
Extracts zip file content to the target directory.
|
static java.io.File |
zip(java.io.File file)
Zips a file or a folder.
|
static java.io.File |
zip(java.lang.String file)
Zips a file or a folder.
|
static java.io.File |
zlib(java.io.File file)
Compresses a file into zlib archive.
|
static java.io.File |
zlib(java.lang.String file)
Compresses a file into zlib archive.
|
public static final java.lang.String ZIP_EXT
public static final java.lang.String GZIP_EXT
public static final java.lang.String ZLIB_EXT
public static java.io.File zlib(java.lang.String file) throws java.io.IOException
java.io.IOException
public static java.io.File zlib(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.io.File gzip(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static java.io.File gzip(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.io.File ungzip(java.lang.String file) throws java.io.IOException
java.io.IOException
public static java.io.File ungzip(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.io.File zip(java.lang.String file) throws java.io.IOException
java.io.IOException
zip(java.io.File)
public static java.io.File zip(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.util.List<java.lang.String> listZip(java.io.File zipFile) throws java.io.IOException
java.io.IOException
public static void unzip(java.lang.String zipFile, java.lang.String destDir, java.lang.String... patterns) throws java.io.IOException
java.io.IOException
unzip(java.io.File, java.io.File, String...)
public static void unzip(java.io.File zipFile, java.io.File destDir, java.lang.String... patterns) throws java.io.IOException
zipFile
- zip filedestDir
- destination directorypatterns
- optional wildcard patterns of files to extract, may be null
java.io.IOException
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.IOException
zos
- zip output streamfile
- file or folder to addpath
- relative path of file entry; if null
files name will be used insteadcomment
- optional commentrecursive
- when set to true
content of added folders will be added, toojava.io.IOException
public static void addToZip(java.util.zip.ZipOutputStream zos, byte[] content, java.lang.String path, java.lang.String comment) throws java.io.IOException
java.io.IOException
public static void addFolderToZip(java.util.zip.ZipOutputStream zos, java.lang.String path, java.lang.String comment) throws java.io.IOException
java.io.IOException
public static void close(java.util.zip.ZipFile zipFile)
Copyright © 2003-present Jodd Team