Class ZipUtils


  • public final class ZipUtils
    extends Object
    Utilities for interfacing with the (fairly low-level) java.util.zip package.
    • Method Detail

      • zipDirectory

        public static void zipDirectory​(File dir,
                                        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​(File zipFile,
                                 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​(File fromDir,
                                     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 successful, the directory will not be created.
      • gunzipFiles

        public static void gunzipFiles​(File fromDir,
                                       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​(File fromFile,
                                      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.