org.codehaus.plexus.archiver.zip

Class AbstractZipArchiver

Implemented Interfaces:
Archiver
Known Direct Subclasses:
ZipArchiver

public abstract class AbstractZipArchiver
extends AbstractArchiver

Version:
$Revision: 2436 $ $Date: 2005-09-01 13:20:41 -0400 (Thu, 01 Sep 2005) $

Field Summary

private static long
EMPTY_CRC
protected Hashtable
addedDirs
private Vector
addedFiles
protected boolean
addingNewFiles
true when we are adding new files into the Zip file, as opposed to adding back the unchanged files
protected String
archiveType
private String
comment
private boolean
doCompress
private boolean
doFilesonly
private boolean
doUpdate
protected boolean
doubleFilePass
protected String
duplicate
private String
encoding
Encoding to use for filenames, defaults to the platform's default encoding.
protected Hashtable
entries
private boolean
roundUp
Whether the file modification times will be rounded up to the next even number of seconds.
private boolean
savedDoUpdate
protected boolean
skipWriting

Fields inherited from class org.codehaus.plexus.archiver.AbstractArchiver

DEFAULT_DIR_MODE, DEFAULT_FILE_MODE, defaultDirectoryMode, defaultFileMode, destFile, dirsMap, filesMap, includeEmptyDirs, logger

Fields inherited from interface org.codehaus.plexus.archiver.Archiver

ROLE

Method Summary

protected void
addParentDirs(File baseDir, String entry, ZipOutputStream zOut, String prefix)
Ensure all parent dirs of a given entry have been added.
protected void
addResources(Map resources, ZipOutputStream zOut)
Add the given resources.
protected void
cleanUp()
Do any clean up necessary to allow this instance to be used again.
void
createArchive()
private void
createArchiveMain()
protected boolean
createEmptyZip(File zipFile)
Create an empty zip file
protected void
finalizeZipOutputStream(ZipOutputStream zOut)
method for subclasses to override
String
getComment()
int
getDirMode()
Deprecated. use AbstractArchiver.getDefaultDirectoryMode() instead.
String
getEncoding()
int
getFileMode()
Deprecated. use AbstractArchiver.getDefaultFileMode() instead.
protected Map
getResourcesToAdd(File file)
protected Map
getResourcesToUpdate(File file)
protected void
initZipOutputStream(ZipOutputStream zOut)
method for subclasses to override
boolean
isCompress()
boolean
isFilesonly()
boolean
isInUpdateMode()
boolean
isRoundUp()
void
reset()
Makes this instance reset all attributes to their default values and forget all children.
void
setComment(String comment)
void
setCompress(boolean compress)
void
setDirMode(String octalString)
Deprecated. use AbstractArchiver.setDefaultDirectoryMode(int).
void
setEncoding(String encoding)
void
setFileMode(String octalString)
Deprecated. use AbstractArchiver.setDefaultFileMode(int) instead.
void
setFilesonly(boolean f)
If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.
void
setRoundUp(boolean r)
Whether the file modification times will be rounded up to the next even number of seconds.
void
setUpdateMode(boolean update)
protected void
zipDir(File dir, ZipOutputStream zOut, String vPath, int mode)
protected void
zipFile(InputStream in, ZipOutputStream zOut, String vPath, long lastModified, File fromArchive, int mode)
Adds a new entry to the archive, takes care of duplicates as well.
protected void
zipFile(ArchiveEntry entry, ZipOutputStream zOut, String vPath)
Method that gets called when adding from java.io.File instances.

Methods inherited from class org.codehaus.plexus.archiver.AbstractArchiver

addDirectory, addDirectory, addDirectory, addDirectory, addFile, addFile, getDefaultDirectoryMode, getDefaultFileMode, getDestFile, getDirs, getFiles, getIncludeEmptyDirs, getLogger, setDefaultDirectoryMode, setDefaultFileMode, setDestFile, setIncludeEmptyDirs

Field Details

EMPTY_CRC

private static final long EMPTY_CRC

addedDirs

protected Hashtable addedDirs

addedFiles

private Vector addedFiles

addingNewFiles

protected boolean addingNewFiles
true when we are adding new files into the Zip file, as opposed to adding back the unchanged files

archiveType

protected String archiveType

comment

private String comment

doCompress

private boolean doCompress

doFilesonly

private boolean doFilesonly

doUpdate

private boolean doUpdate

doubleFilePass

protected boolean doubleFilePass

duplicate

protected String duplicate

encoding

private String encoding
Encoding to use for filenames, defaults to the platform's default encoding.

entries

protected Hashtable entries

roundUp

private boolean roundUp
Whether the file modification times will be rounded up to the next even number of seconds.

savedDoUpdate

private boolean savedDoUpdate

skipWriting

protected boolean skipWriting

Method Details

addParentDirs

protected final void addParentDirs(File baseDir,
                                   String entry,
                                   ZipOutputStream zOut,
                                   String prefix)
            throws IOException
Ensure all parent dirs of a given entry have been added.

addResources

protected final void addResources(Map resources,
                                  ZipOutputStream zOut)
            throws IOException,
                   ArchiverException
Add the given resources.
Parameters:
resources - the resources to add
zOut - the stream to write to

cleanUp

protected void cleanUp()
Do any clean up necessary to allow this instance to be used again.

When we get here, the Zip file has been closed and all we need to do is to reset some globals.

This method will only reset globals that have been changed during execute(), it will not alter the attributes or nested child elements. If you want to reset the instance so that you can later zip a completely different set of files, you must use the reset method.


createArchive

public void createArchive()
            throws ArchiverException,
                   IOException
Specified by:
createArchive in interface Archiver

createArchiveMain

private void createArchiveMain()
            throws ArchiverException

createEmptyZip

protected boolean createEmptyZip(File zipFile)
            throws ArchiverException
Create an empty zip file
Returns:
true for historic reasons

finalizeZipOutputStream

protected void finalizeZipOutputStream(ZipOutputStream zOut)
            throws IOException,
                   ArchiverException
method for subclasses to override

getComment

public String getComment()

getDirMode

public int getDirMode()

Deprecated. use AbstractArchiver.getDefaultDirectoryMode() instead.


getEncoding

public String getEncoding()

getFileMode

public int getFileMode()

Deprecated. use AbstractArchiver.getDefaultFileMode() instead.


getResourcesToAdd

protected Map getResourcesToAdd(File file)
            throws IOException

getResourcesToUpdate

protected Map getResourcesToUpdate(File file)
            throws IOException

initZipOutputStream

protected void initZipOutputStream(ZipOutputStream zOut)
            throws IOException,
                   ArchiverException
method for subclasses to override

isCompress

public boolean isCompress()

isFilesonly

public boolean isFilesonly()

isInUpdateMode

public boolean isInUpdateMode()

isRoundUp

public boolean isRoundUp()

reset

public void reset()
Makes this instance reset all attributes to their default values and forget all children.

setComment

public void setComment(String comment)

setCompress

public void setCompress(boolean compress)

setDirMode

public void setDirMode(String octalString)

Deprecated. use AbstractArchiver.setDefaultDirectoryMode(int).

A 3 digit octal string, specify the user, group and other modes in the standard Unix fashion; optional, default=0755

setEncoding

public void setEncoding(String encoding)

setFileMode

public void setFileMode(String octalString)

Deprecated. use AbstractArchiver.setDefaultFileMode(int) instead.

A 3 digit octal string, specify the user, group and other modes in the standard Unix fashion; optional, default=0644

setFilesonly

public void setFilesonly(boolean f)
If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.

setRoundUp

public void setRoundUp(boolean r)
Whether the file modification times will be rounded up to the next even number of seconds.

Zip archives store file modification times with a granularity of two seconds, so the times will either be rounded up or down. If you round down, the archive will always seem out-of-date when you rerun the task, so the default is to round up. Rounding up may lead to a different type of problems like JSPs inside a web archive that seem to be slightly more recent than precompiled pages, rendering precompilation useless.


setUpdateMode

public void setUpdateMode(boolean update)

zipDir

protected void zipDir(File dir,
                      ZipOutputStream zOut,
                      String vPath,
                      int mode)
            throws IOException

zipFile

protected void zipFile(InputStream in,
                       ZipOutputStream zOut,
                       String vPath,
                       long lastModified,
                       File fromArchive,
                       int mode)
            throws IOException,
                   ArchiverException
Adds a new entry to the archive, takes care of duplicates as well.
Parameters:
in - the stream to read data for the entry from.
zOut - the stream to write to.
vPath - the name this entry shall have in the archive.
lastModified - last modification time for the entry.
fromArchive - the original archive we are copying this entry from, will be null if we are not copying from an archive.
mode - the Unix permissions to set.

zipFile

protected void zipFile(ArchiveEntry entry,
                       ZipOutputStream zOut,
                       String vPath)
            throws IOException,
                   ArchiverException
Method that gets called when adding from java.io.File instances.

This implementation delegates to the six-arg version.

Parameters:
entry - the file to add to the archive
zOut - the stream to write to
vPath - the name this entry shall have in the archive