Package adams.core.io
Class ZipUtils
- java.lang.Object
-
- adams.core.io.ZipUtils
-
public class ZipUtils extends Object
A helper class for ZIP-file related tasks.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description ZipUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringcompress(File output, File[] files)Creates a zip file from the specified files.static Stringcompress(File output, File[] files, int bufferSize)Creates a zip file from the specified files.static Stringcompress(File output, File[] files, String stripRegExp, int bufferSize)Creates a zip file from the specified files.static List<File>decompress(File input, File outputDir)Unzips the files in a ZIP file.static List<File>decompress(File input, File outputDir, boolean createDirs)Unzips the files in a ZIP file.static List<File>decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch)Unzips the files in a ZIP file.static List<File>decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize)Unzips the files in a ZIP file.static List<File>decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize, MessageCollection errors)Unzips the files in a ZIP file.static booleandecompress(File input, String archiveFile, File output)Unzips the specified file from a ZIP file.static booleandecompress(File input, String archiveFile, File output, boolean createDirs)Unzips the specified file from a ZIP file.static booleandecompress(File input, String archiveFile, File output, boolean createDirs, int bufferSize, MessageCollection errors)Unzips the specified file from a ZIP file.static booleanisZipCompressed(byte[] data)Checks whether the array is zip compressed.static booleanisZipCompressed(File file)Checks whether the file is zip compressed.static List<File>listFiles(File input)Lists the files stored in the ZIP file.static List<File>listFiles(File input, boolean listDirs)Lists the files stored in the ZIP file.
-
-
-
Field Detail
-
LOGGER
protected static Logger LOGGER
for logging errors.
-
-
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 generatefiles- the files to store in the zip file- Returns:
- null if successful, otherwise error message
-
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 generatefiles- the files to store in the zip filebufferSize- the buffer size to use- Returns:
- null if successful, otherwise error message
-
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 generatefiles- the files to store in the zip filestripRegExp- the regular expression used to strip the file names (only applied to the directory!)bufferSize- the buffer size to use- Returns:
- null if successful, otherwise error message
-
decompress
public static List<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 unzipoutputDir- the directory where to store the extracted files- Returns:
- the successfully extracted files
-
decompress
public static List<File> decompress(File input, File outputDir, boolean createDirs)
Unzips the files in a ZIP file.- Parameters:
input- the ZIP file to unzipoutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the ZIP file- Returns:
- the successfully extracted files
-
decompress
public static List<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 unzipoutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the ZIP filematch- the regular expression that the files are matched againstinvertMatch- whether to invert the matching sense- Returns:
- the successfully extracted files
-
decompress
public static List<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 unzipoutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the ZIP filematch- the regular expression that the files are matched againstinvertMatch- whether to invert the matching sensebufferSize- the buffer size to use- Returns:
- the successfully extracted files
-
decompress
public static List<File> decompress(File input, File outputDir, boolean createDirs, BaseRegExp match, boolean invertMatch, int bufferSize, MessageCollection 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 unzipoutputDir- the directory where to store the extracted filescreateDirs- whether to re-create the directory structure from the ZIP filematch- the regular expression that the files are matched againstinvertMatch- whether to invert the matching sensebufferSize- the buffer size to useerrors- for storing potential errors- Returns:
- the successfully extracted files
-
decompress
public static boolean decompress(File input, String archiveFile, File output)
Unzips the specified file 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 unziparchiveFile- the file from the archive to extractoutput- the name of the output file- Returns:
- whether file was successfully extracted
-
decompress
public static boolean decompress(File input, String archiveFile, File output, boolean createDirs)
Unzips the specified file from a ZIP file.- Parameters:
input- the ZIP file to unziparchiveFile- the file from the archive to extractoutput- the name of the output filecreateDirs- whether to create the directory structure represented by output file- Returns:
- whether file was successfully extracted
-
decompress
public static boolean decompress(File input, String archiveFile, File output, boolean createDirs, int bufferSize, MessageCollection errors)
Unzips the specified file from a ZIP file.- Parameters:
input- the ZIP file to unziparchiveFile- the file from the archive to extractoutput- the name of the output filecreateDirs- whether to create the directory structure represented by output filebufferSize- the buffer size to useerrors- for storing potential errors- Returns:
- whether file was successfully extracted
-
listFiles
public static List<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 List<File> listFiles(File input, boolean listDirs)
Lists the files stored in the ZIP file.- Parameters:
input- the ZIP file to obtain the file list fromlistDirs- whether to include directories in the list- Returns:
- the stored files
-
isZipCompressed
public static boolean isZipCompressed(File file)
Checks whether the file is zip compressed. See: https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers- Parameters:
file- the file to inspect- Returns:
- true if gzip
-
isZipCompressed
public static boolean isZipCompressed(byte[] data)
Checks whether the array is zip compressed. See: https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers- Parameters:
data- the data to inspect- Returns:
- true if gzip
-
-