dk.netarkivet.common.utils
Class ZipUtils

java.lang.Object
  extended by dk.netarkivet.common.utils.ZipUtils

public class ZipUtils
extends java.lang.Object

Utilities for interfacing with the (fairly low-level) java.util.zip package


Field Summary
static java.lang.String GZIP_SUFFIX
          The standard suffix for a gzipped file.
 
Constructor Summary
ZipUtils()
           
 
Method Summary
static void gunzipFile(java.io.File fromFile, java.io.File toFile)
          Gunzip a single gzipped file into the given file.
static void gunzipFiles(java.io.File fromDir, java.io.File toDir)
          Gunzip all .gz files in a given directory into another.
static void gzipFiles(java.io.File fromDir, java.io.File toDir)
          GZip each of the files in fromDir, placing the result in toDir (which will be created) with names having .gz appended.
static void unzip(java.io.File zipFile, java.io.File toDir)
          Unzip a zipFile into a directory.
static void zipDirectory(java.io.File dir, java.io.File into)
          Zip the contents of a directory into a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GZIP_SUFFIX

public static final java.lang.String GZIP_SUFFIX
The standard suffix for a gzipped file.

See Also:
Constant Field Values
Constructor Detail

ZipUtils

public ZipUtils()
Method Detail

zipDirectory

public static void zipDirectory(java.io.File dir,
                                java.io.File into)
Zip the contents of a directory into a file. Does *not* zip recursively.

Parameters:
dir - The directory to zip.
into - The (zip) file to create. The name should typically end in .zip, but that is not required.

unzip

public static void unzip(java.io.File zipFile,
                         java.io.File toDir)
Unzip a zipFile into a directory. This will create subdirectories as needed.

Parameters:
zipFile - The file to unzip
toDir - The directory to create the files under. This directory will be created if necessary. Files in it will be overwritten if the filenames match.

gzipFiles

public static void gzipFiles(java.io.File fromDir,
                             java.io.File toDir)
GZip each of the files in fromDir, placing the result in toDir (which will be created) with names having .gz appended. All non-file (directory, link, etc) entries in the source directory will be skipped with a quiet little log message.

Parameters:
fromDir - An existing directory
toDir - A directory where gzipped files will be placed. This directory must not previously exist. If the operation is not successfull, the directory will not be created.

gunzipFiles

public static void gunzipFiles(java.io.File fromDir,
                               java.io.File toDir)
Gunzip all .gz files in a given directory into another. Files in fromDir not ending in .gz or not real files will be skipped with a log entry.

Parameters:
fromDir - The directory containing .gz files
toDir - The directory to place the unzipped files in. This directory must not exist beforehand.
Throws:
IOFailure - if there are problems creating the output directory or gunzipping the files.

gunzipFile

public static void gunzipFile(java.io.File fromFile,
                              java.io.File toFile)
Gunzip a single gzipped file into the given file. Unlike with the gzip() command-line tool, the original file is not deleted.

Parameters:
fromFile - A gzipped file to unzip.
toFile - The file that the contents of fromFile should be gunzipped into. This file must be in an existing directory. Existing contents of this file will be overwritten.