adams.core.io
Class ZipUtils

java.lang.Object
  extended by adams.core.io.ZipUtils

public class ZipUtils
extends Object

A helper class for ZIP-file related tasks.

Version:
$Revision: 4584 $
Author:
fracpete (fracpete at waikato dot ac dot nz)

Constructor Summary
ZipUtils()
           
 
Method Summary
static String compress(File output, File[] files)
          Creates a zip file from the specified files.
static String compress(File output, File[] files, int bufferSize)
          Creates a zip file from the specified files.
static String compress(File output, File[] files, String stripRegExp, int bufferSize)
          Creates a zip file from the specified files.
static Vector<File> decompress(File input, File outputDir)
          Unzips the files in a ZIP file.
static Vector<File> decompress(File input, File outputDir, boolean createDirs)
          Unzips the files in a ZIP file.
static Vector<File> decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch)
          Unzips the files in a ZIP file.
static Vector<File> decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize)
          Unzips the files in a ZIP file.
static Vector<File> decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize, StringBuilder errors)
          Unzips the files in a ZIP file.
static boolean decompress(File input, String archiveFile, File output)
          Unzips the specified from a ZIP file.
static boolean decompress(File input, String archiveFile, File output, boolean createDirs)
          Unzips the specified from a ZIP file.
static boolean decompress(File input, String archiveFile, File output, boolean createDirs, int bufferSize, StringBuilder errors)
          Unzips the specified from a ZIP file.
static Vector<File> listFiles(File input)
          Lists the files stored in the ZIP file.
static Vector<File> listFiles(File input, boolean listDirs)
          Lists the files stored in the ZIP file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipUtils

public ZipUtils()
Method Detail

compress

public static String compress(File output,
                              File[] files)
Creates a zip file from the specified files.

Parameters:
output - the output file to generate
files - the files to store in the zip file
Returns:
null if successful, otherwise error message
See Also:
compress(File, File[], int)

compress

public static String compress(File output,
                              File[] files,
                              int bufferSize)
Creates a zip file from the specified files.

Parameters:
output - the output file to generate
files - the files to store in the zip file
bufferSize - the buffer size to use
Returns:
null if successful, otherwise error message
See Also:
compress(File, File[], String, int)

compress

public static String compress(File output,
                              File[] files,
                              String stripRegExp,
                              int bufferSize)
Creates a zip file from the specified files.

Parameters:
output - the output file to generate
files - the files to store in the zip file
stripRegExp - the regular expression used to strip the file names
bufferSize - the buffer size to use
Returns:
null if successful, otherwise error message

decompress

public static Vector<File> decompress(File input,
                                      File outputDir)
Unzips the files in a ZIP file. Does not recreate the directory structure stored in the ZIP file.

Parameters:
input - the ZIP file to unzip
outputDir - the directory where to store the extracted files
Returns:
the successfully extracted files
See Also:
decompress(File, File, boolean)

decompress

public static Vector<File> decompress(File input,
                                      File outputDir,
                                      boolean createDirs)
Unzips the files in a ZIP file.

Parameters:
input - the ZIP file to unzip
outputDir - the directory where to store the extracted files
createDirs - whether to re-create the directory structure from the ZIP file
Returns:
the successfully extracted files
See Also:
#decompress(File, File, boolean, String, boolean)

decompress

public static Vector<File> decompress(File input,
                                      File outputDir,
                                      boolean createDirs,
                                      BaseRegExp match,
                                      boolean invertMatch)
Unzips the files in a ZIP file. Files can be filtered based on their filename, using a regular expression (the matching sense can be inverted).

Parameters:
input - the ZIP file to unzip
outputDir - the directory where to store the extracted files
createDirs - whether to re-create the directory structure from the ZIP file
match - the regular expression that the files are matched against
invertMatch - whether to invert the matching sense
Returns:
the successfully extracted files
See Also:
#decompress(File, File, boolean, String, boolean, int)

decompress

public static Vector<File> decompress(File input,
                                      File outputDir,
                                      boolean createDirs,
                                      BaseRegExp match,
                                      boolean invertMatch,
                                      int bufferSize)
Unzips the files in a ZIP file. Files can be filtered based on their filename, using a regular expression (the matching sense can be inverted).

Parameters:
input - the ZIP file to unzip
outputDir - the directory where to store the extracted files
createDirs - whether to re-create the directory structure from the ZIP file
match - the regular expression that the files are matched against
invertMatch - whether to invert the matching sense
bufferSize - the buffer size to use
Returns:
the successfully extracted files

decompress

public static Vector<File> decompress(File input,
                                      File outputDir,
                                      boolean createDirs,
                                      BaseRegExp match,
                                      boolean invertMatch,
                                      int bufferSize,
                                      StringBuilder errors)
Unzips the files in a ZIP file. Files can be filtered based on their filename, using a regular expression (the matching sense can be inverted).

Parameters:
input - the ZIP file to unzip
outputDir - the directory where to store the extracted files
createDirs - whether to re-create the directory structure from the ZIP file
match - the regular expression that the files are matched against
invertMatch - whether to invert the matching sense
bufferSize - the buffer size to use
errors - for storing potential errors
Returns:
the successfully extracted files

decompress

public static boolean decompress(File input,
                                 String archiveFile,
                                 File output)
Unzips the specified from a ZIP file. Does not create any directories in case the parent directories of "output" don't exist yet.

Parameters:
input - the ZIP file to unzip
archiveFile - the file from the archive to extract
output - the name of the output file
Returns:
the successfully extracted files

decompress

public static boolean decompress(File input,
                                 String archiveFile,
                                 File output,
                                 boolean createDirs)
Unzips the specified from a ZIP file.

Parameters:
input - the ZIP file to unzip
archiveFile - the file from the archive to extract
output - the name of the output file
createDirs - whether to create the directory structure represented by output file
Returns:
the successfully extracted files

decompress

public static boolean decompress(File input,
                                 String archiveFile,
                                 File output,
                                 boolean createDirs,
                                 int bufferSize,
                                 StringBuilder errors)
Unzips the specified from a ZIP file.

Parameters:
input - the ZIP file to unzip
archiveFile - the file from the archive to extract
output - the name of the output file
createDirs - whether to create the directory structure represented by output file
bufferSize - the buffer size to use
errors - for storing potential errors
Returns:
the successfully extracted files

listFiles

public static Vector<File> listFiles(File input)
Lists the files stored in the ZIP file. Lists directories automatically.

Parameters:
input - the ZIP file to obtain the file list from
Returns:
the stored files

listFiles

public static Vector<File> listFiles(File input,
                                     boolean listDirs)
Lists the files stored in the ZIP file.

Parameters:
input - the ZIP file to obtain the file list from
listDirs - whether to include directories in the list
Returns:
the stored files


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.