Constructor and Description |
---|
Archive(ZipOutputStream zip)
Constructs a helper class which will allow to add files to the
specified destination zip stream.
|
Modifier and Type | Method and Description |
---|---|
void |
add(File srcFile,
File baseDir)
Equivalent to
add(srcFile, baseDir, false) . |
void |
add(File srcFile,
File baseDir,
boolean store)
Adds specified file to the zip archive.
|
void |
addAll(File srcDir,
FilenameFilter filter,
File baseDir)
Adds all files contained in specified directory to the zip archive.
|
void |
close()
Closes both the underlying destination zip stream and its output
stream.
|
void |
finish()
Closes the underlying destination zip stream without closing its
output stream.
|
ZipOutputStream |
getZipOutputStream()
Returns the underlying destination zip stream.
|
public Archive(ZipOutputStream zip)
public ZipOutputStream getZipOutputStream()
public void add(File srcFile, File baseDir) throws IOException, IllegalArgumentException
add(srcFile, baseDir, false)
.IOException
IllegalArgumentException
public void add(File srcFile, File baseDir, boolean store) throws IOException, IllegalArgumentException
Will automatically add directory entries if needed to. For example, when adding "/tmp/foo/bar/gee.txt" relatively to "/tmp", it will automatically add directory entries "foo/" and "foo/bar/".
Note that this method does not check that a source file is added only once to the archive. It is the resposability of the client code to check this.
srcFile
- file or directory to be addedbaseDir
- ancestor directory of srcFile. Used to
compute the path used to access srcFile in the zip
archive.
Example: if srcFile is C:\temp\doc\chapter1\chapter1.xml and baseDir is C:\temp\doc, the zip archive will contain path chapter1/chapter1.xml.
store
- if true
, just store, that is do not
compress, specified file.
Ignored if srcFile is a directory.IOException
- if there is an I/O problem during the
creation of the zip archiveIllegalArgumentException
- if baseDir does not
seem to be an ancestor directory of srcFile. Note that
this may happen simply because baseDir and/or
srcFile are not in canonical formpublic void finish() throws IOException
getZipOutputStream().finish()
.IOException
public void close() throws IOException
getZipOutputStream().close()
.IOException
public void addAll(File srcDir, FilenameFilter filter, File baseDir) throws IOException
srcDir
- directory containing the files to be zipped. This
directory is traversed recursively.filter
- may be used to filter the files to be zipped. May be
null
, in which case, all the files and directory
contained in srcDir are to be zipped.baseDir
- ancestor directory of srcDir. May be equal
to srcDir. Used to compute the paths used to access the
files coming from srcDir in the zip archive.IOException
- if there is an I/O problem during the
creation of the zip archiveadd(java.io.File, java.io.File)