Class ZipHandler
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.defaultInstantiators.ZipHandler
-
- Direct Known Subclasses:
JarHandler
public class ZipHandler extends java.lang.ObjectImplements a handler function for ZIP files (which is prepared for handling JAR files in a similar way).- Author:
- Holger Eichelberger, kroeher
-
-
Constructor Summary
Constructors Constructor Description ZipHandler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<java.io.File>add(java.io.File base, java.util.List<java.io.File> files, java.io.File zip)Adds a set offiles(relative tobase) to the ZIP filezip.protected voidadditionalUnpacking(java.util.zip.ZipInputStream zis, java.io.File target, java.util.List<java.io.File> files)Performs additional unpacking (called byunpack(File, File, String, List)).protected java.util.zip.ZipEntrycreateEntry(java.lang.String name, java.io.File file)Creates a ZIP entry.protected java.util.zip.ZipInputStreamcreateInputStream(java.io.InputStream in)Creates a ZIP input stream forin.protected java.util.zip.ZipOutputStreamcreateOutputStream(java.io.OutputStream out)Creates a ZIP output stream forout.protected booleaninclude(java.io.File file)Returns whetherfileshall be included in repackaging a JAR file.private java.lang.StringmakeRelative(java.lang.String basePath, java.io.File file)Makes a file path relative to the givenbasePath.private static booleanmatches(java.util.zip.ZipEntry entry, java.lang.String pattern)Checks whether anentrymatches afilterexpression.private voidpackInto(java.lang.String basePath, java.io.File source, java.util.zip.ZipOutputStream out, java.util.Set<java.lang.String> done)Packs the files insourceintoout.java.io.Fileunpack(java.io.File zip, java.io.File target, java.lang.String pattern, java.util.List<java.io.File> files)Unpacks an ZIP file totarget.
-
-
-
Method Detail
-
add
public java.util.List<java.io.File> add(java.io.File base, java.util.List<java.io.File> files, java.io.File zip) throws java.io.IOExceptionAdds a set offiles(relative tobase) to the ZIP filezip. Ifzipexists,filesare added tozip, i.e.,zipis overwritten with an updated version. Ifzipdoes not exist, a newziparchive will be created.- Parameters:
base- the base directory used for makingfilesrelativefiles- the files to be put intozipzip- the ZIP file- Returns:
- the modified files (actually only ZIP)
- Throws:
java.io.IOException- in case that serious I/O problems occurred
-
makeRelative
private java.lang.String makeRelative(java.lang.String basePath, java.io.File file)Makes a file path relative to the givenbasePath.- Parameters:
basePath- the base pathfile- the file to be made relative- Returns:
- the relative path (if
filecan be made relative)
-
createInputStream
protected java.util.zip.ZipInputStream createInputStream(java.io.InputStream in) throws java.io.IOExceptionCreates a ZIP input stream forin. This method shall be overridden for specialized ZIP types, e.g., JAR.- Parameters:
in- the input stream to create the ZIP stream for.- Returns:
- the ZIP input stream
- Throws:
java.io.IOException- in case that creating the input stream fails
-
createOutputStream
protected java.util.zip.ZipOutputStream createOutputStream(java.io.OutputStream out) throws java.io.IOExceptionCreates a ZIP output stream forout. This method shall be overridden for specialized ZIP types, e.g., JAR.- Parameters:
out- the output stream to create the ZIP stream for.- Returns:
- the ZIP output stream
- Throws:
java.io.IOException- in case that creating the output stream fails
-
createEntry
protected java.util.zip.ZipEntry createEntry(java.lang.String name, java.io.File file)Creates a ZIP entry. This method shall be overridden for specialized ZIP types, e.g., JAR.- Parameters:
name- the name of the entryfile- the underlying file- Returns:
- the ZIP entry
-
unpack
public java.io.File unpack(java.io.File zip, java.io.File target, java.lang.String pattern, java.util.List<java.io.File> files) throws java.io.IOExceptionUnpacks an ZIP file totarget.- Parameters:
zip- the ZIP file to be unpacked (nothing happens ifzipdoes not exist)target- the target directory where to unpack (a temporary directory is created iftargetis null)pattern- an optional ANT pattern used as a filter expression, typically a specific folder or package. May benullif no filter is required.files- the unpacked files (may contain directories, modified as a side effect, may be null if the unpacked files shall not be collected)- Returns:
- the target directory, in particular a newly created temporary directory
- Throws:
java.io.IOException- in case that unpacking fails for some reason
-
matches
private static boolean matches(java.util.zip.ZipEntry entry, java.lang.String pattern)Checks whether anentrymatches afilterexpression.- Parameters:
entry- the Zip entrypattern- an optional ANT pattern used as a filter expression, typically a specific folder or package. May benullif no filter is required.- Returns:
trueifentrymatchesfilterorfilterisnull,falseotherwise
-
additionalUnpacking
protected void additionalUnpacking(java.util.zip.ZipInputStream zis, java.io.File target, java.util.List<java.io.File> files) throws java.io.IOExceptionPerforms additional unpacking (called byunpack(File, File, String, List)).- Parameters:
zis- the ZIP input streamtarget- the target directory where to unpack (a temporary directory is created iftargetis null)files- the unpacked files (may contain directories, modified as a side effect, may be null if the unpacked files shall not be collected)- Throws:
java.io.IOException- in case that unpacking fails for some reason
-
packInto
private void packInto(java.lang.String basePath, java.io.File source, java.util.zip.ZipOutputStream out, java.util.Set<java.lang.String> done) throws java.io.IOExceptionPacks the files insourceintoout.- Parameters:
basePath- the base path (shall be the absolute path ofsourcefor the first callsource- the source directory to take the files fromout- the ZIP output stream to write the files intodone- already processed ZIP paths- Throws:
java.io.IOException- in case that reading or creating files fails
-
include
protected boolean include(java.io.File file)
Returns whetherfileshall be included in repackaging a JAR file.- Parameters:
file- the file to be considered- Returns:
trueiffileshall be packed,falseelse
-
-