jodd.io
Class ZipUtil

java.lang.Object
  extended by jodd.io.ZipUtil

public class ZipUtil
extends java.lang.Object

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
static java.lang.String GZIP_EXT
           
static java.lang.String ZIP_EXT
           
static java.lang.String ZLIB_EXT
           
 
Constructor Summary
ZipUtil()
           
 
Method Summary
static void addToZip(java.util.zip.ZipOutputStream zos, java.io.File file)
           
static void addToZip(java.util.zip.ZipOutputStream zos, java.io.File file, java.lang.String relativeName)
           
static void addToZip(java.util.zip.ZipOutputStream zos, java.io.File file, java.lang.String relativeName, java.lang.String comment)
           
static void addToZip(java.util.zip.ZipOutputStream zos, java.lang.String file)
           
static void addToZip(java.util.zip.ZipOutputStream zos, java.lang.String fileName, java.lang.String relativeName)
           
static void addToZip(java.util.zip.ZipOutputStream zos, java.lang.String fileName, java.lang.String relativeName, java.lang.String comment)
           
static void close(java.util.zip.ZipFile zipFile)
          Closes zip file safely.
static java.util.zip.ZipOutputStream createZip(java.io.File zip)
          Creates and opens zip output stream of a zip file.
static java.util.zip.ZipOutputStream createZip(java.lang.String zipFile)
           
static void gzip(java.io.File file)
          Compresses a file into gzip archive.
static void gzip(java.lang.String fileName)
          Compresses a file into gzip archive.
static void ungzip(java.io.File file)
          Decompress gzip archive.
static void ungzip(java.lang.String file)
          Decompress gzip archive.
static void unzip(java.io.File zipFile, java.io.File destDir)
          Extracts zip file to the target directory.
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)
          Extracts zip file content 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 void zip(java.io.File file)
          Zips a file or a folder.
static void zip(java.lang.String file)
          Zips a file or a folder.
static void zlib(java.io.File file)
          Compresses a file into zlib archive.
static void zlib(java.lang.String file)
          Compresses a file into zlib archive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

ZipUtil

public ZipUtil()
Method Detail

zlib

public static void zlib(java.lang.String file)
                 throws java.io.IOException
Compresses a file into zlib archive.

Throws:
java.io.IOException

zlib

public static void zlib(java.io.File file)
                 throws java.io.IOException
Compresses a file into zlib archive.

Throws:
java.io.IOException

gzip

public static void gzip(java.lang.String fileName)
                 throws java.io.IOException
Compresses a file into gzip archive.

Throws:
java.io.IOException

gzip

public static void gzip(java.io.File file)
                 throws java.io.IOException
Compresses a file into gzip archive.

Throws:
java.io.IOException

ungzip

public static void ungzip(java.lang.String file)
                   throws java.io.IOException
Decompress gzip archive.

Throws:
java.io.IOException

ungzip

public static void ungzip(java.io.File file)
                   throws java.io.IOException
Decompress gzip archive.

Throws:
java.io.IOException

zip

public static void zip(java.lang.String file)
                throws java.io.IOException
Zips a file or a folder.

Throws:
java.io.IOException

zip

public static void zip(java.io.File file)
                throws java.io.IOException
Zips a file or a folder.

Throws:
java.io.IOException

unzip

public static void unzip(java.lang.String zipFile,
                         java.lang.String destDir)
                  throws java.io.IOException
Extracts 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.lang.String zipFile,
                         java.lang.String destDir,
                         java.lang.String... patterns)
                  throws java.io.IOException
Extracts 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)
                  throws java.io.IOException
Extracts zip file 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.IOException
Extracts zip file to the target directory. If patterns are provided only matched paths are extracted.

Parameters:
zipFile - zip file
destDir - destination directory
patterns - wildcard patterns, may be null
Throws:
java.io.IOException

createZip

public static java.util.zip.ZipOutputStream createZip(java.lang.String zipFile)
                                               throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException
See Also:
createZip(java.io.File)

createZip

public static java.util.zip.ZipOutputStream createZip(java.io.File zip)
                                               throws java.io.FileNotFoundException
Creates and opens zip output stream of a zip file. If zip file exist it will be recreated.

Throws:
java.io.FileNotFoundException

addToZip

public static void addToZip(java.util.zip.ZipOutputStream zos,
                            java.io.File file)
                     throws java.io.IOException
Throws:
java.io.IOException

addToZip

public static void addToZip(java.util.zip.ZipOutputStream zos,
                            java.lang.String file)
                     throws java.io.IOException
Throws:
java.io.IOException

addToZip

public static void addToZip(java.util.zip.ZipOutputStream zos,
                            java.io.File file,
                            java.lang.String relativeName)
                     throws java.io.IOException
Throws:
java.io.IOException

addToZip

public static void addToZip(java.util.zip.ZipOutputStream zos,
                            java.lang.String fileName,
                            java.lang.String relativeName)
                     throws java.io.IOException
Throws:
java.io.IOException

addToZip

public static void addToZip(java.util.zip.ZipOutputStream zos,
                            java.lang.String fileName,
                            java.lang.String relativeName,
                            java.lang.String comment)
                     throws java.io.IOException
Throws:
java.io.IOException

addToZip

public static void addToZip(java.util.zip.ZipOutputStream zos,
                            java.io.File file,
                            java.lang.String relativeName,
                            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.



Copyright © 2003-2012 Jodd Team