public class ZipUtils
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ZipUtils.ZipFileVisitor
A simple walker which will visit all Zip-entries in the given InputStream.
|
| Constructor and Description |
|---|
ZipUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
extractZip(java.io.File zip,
java.io.File toDir)
Extracts all files in the specified ZIP file and stores them in the
denoted directory.
|
static void |
extractZip(java.io.InputStream zip,
java.io.File toDir)
Extracts all files in the ZIP file passed as InputStream and stores them in the
denoted directory.
|
static void |
findZip(java.lang.String zipName,
java.io.InputStream zipInput,
java.io.FileFilter searchFilter,
java.util.List<java.lang.String> results)
Looks in the ZIP file available via zipInput for files matching the provided file-filter,
recursing into sub-ZIP files.
|
static java.io.InputStream |
getZipContentsRecursive(java.lang.String file)
Get a stream of the noted file which potentially resides inside ZIP files.
|
static java.lang.String |
getZipStringContentsRecursive(java.lang.String file)
Get the text-contents of the noted file.
|
static boolean |
isFileInZip(java.lang.String name)
Checks if the string denotes a file inside a ZIP file using the notation
used for getZipContentsRecursive().
|
static boolean |
isZip(java.lang.String fileName)
Determines if the file has an extension known to be a ZIP file,
currently this includes .zip, .jar, .war, .ear, .aar
|
static void |
replaceInZip(java.io.File zip,
java.lang.String file,
java.lang.String data,
java.lang.String encoding)
Replaces the specified file in the provided ZIP file with the
provided content.
|
static void |
replaceInZip(java.lang.String zipFile,
java.lang.String data,
java.lang.String encoding)
Replace the file denoted by the zipFile with the provided data.
|
public static boolean isZip(java.lang.String fileName)
fileName - The name of the file to check.public static boolean isFileInZip(java.lang.String name)
name - The name to checkpublic static void findZip(java.lang.String zipName,
java.io.InputStream zipInput,
java.io.FileFilter searchFilter,
java.util.List<java.lang.String> results)
throws java.io.IOException
zipName - Name of the file to read, mainly used for building the resulting pointer into the zip-filezipInput - An InputStream which is positioned at the beginning of the zip-file contentssearchFilter - A FileFilter which determines if files in the zip-file are matchedresults - A existing list where found matches are added to.java.io.IOException - If the ZIP file cannot be read, e.g. if it is corrupted.public static java.io.InputStream getZipContentsRecursive(java.lang.String file)
throws java.io.IOException
file - The name of the file to read, files inside zip files are denoted with '!'.java.io.IOException - If the file cannot be found or an error occurs while opening the file.public static java.lang.String getZipStringContentsRecursive(java.lang.String file)
throws java.io.IOException
file - The name of the file to read, files inside zip files are denoted with '!'.java.io.IOException - If the file cannot be found or an error occurs while opening the file.public static final void extractZip(java.io.File zip,
java.io.File toDir)
throws java.io.IOException
zip - The zip-file to processtoDir - Target directory, should already exist.java.io.IOException - Thrown if files can not be read or any other error occurs while handling the Zip-filespublic static final void extractZip(java.io.InputStream zip,
java.io.File toDir)
throws java.io.IOException
zip - An InputStream to read zipped files fromtoDir - Target directory, should already exist.java.io.IOException - Thrown if files can not be read or any other error occurs while handling the Zip-filespublic static void replaceInZip(java.lang.String zipFile,
java.lang.String data,
java.lang.String encoding)
throws java.io.IOException
zipFile - The zip-file to processdata - The string-data to replaceencoding - The encoding that should be used when writing the string data to the filejava.io.IOException - Thrown if files can not be read or any other error occurs while handling the Zip-filespublic static void replaceInZip(java.io.File zip,
java.lang.String file,
java.lang.String data,
java.lang.String encoding)
throws java.io.IOException
zip - The zip-file to processfile - The file to look fordata - The string-data to replaceencoding - The encoding that should be used when writing the string data to the filejava.io.IOException - Thrown if files can not be read or any other error occurs while handling the Zip-files