org.codehaus.plexus.archiver.zip

Class AbstractZipArchiver

public abstract class AbstractZipArchiver extends AbstractArchiver

Version: $Revision: 8217 $ $Date: 2009-05-27 03:56:55 +0300 (Wed, 27 May 2009) $

Field Summary
protected HashtableaddedDirs
protected booleanaddingNewFiles
true when we are adding new files into the Zip file, as opposed to adding back the unchanged files
protected StringarchiveType
protected booleandoubleFilePass
protected Stringduplicate
protected Hashtableentries
protected booleanskipWriting
Method Summary
protected voidaddParentDirs(File baseDir, String entry, ZipOutputStream zOut, String prefix)
Ensure all parent dirs of a given entry have been added.
protected voidaddResources(ResourceIterator resources, ZipOutputStream zOut)
Add the given resources.
protected voidcleanUp()
Do any clean up necessary to allow this instance to be used again.
protected voidclose()
protected booleancreateEmptyZip(File zipFile)
Create an empty zip file
protected voidexecute()
protected voidfinalizeZipOutputStream(ZipOutputStream zOut)
protected StringgetArchiveType()
StringgetComment()
StringgetEncoding()
protected MapgetZipEntryNames(File file)
protected voidinitZipOutputStream(ZipOutputStream zOut)
method for subclasses to override
booleanisCompress()
protected booleanisFileAdded(ArchiveEntry entry, Map entries)
booleanisFilesonly()
protected booleanisFileUpdated(ArchiveEntry entry, Map entries)
booleanisInUpdateMode()
booleanisRoundUp()
booleanisSupportingForced()
method for subclasses to override
voidreset()
Makes this instance reset all attributes to their default values and forget all children.
protected booleanrevert(StringBuffer messageBuffer)
voidsetComment(String comment)
voidsetCompress(boolean compress)
voidsetEncoding(String encoding)
voidsetFilesonly(boolean f)
If true, emulate Sun's jar utility by not adding parent directories; optional, defaults to false.
voidsetRoundUp(boolean r)
Whether the file modification times will be rounded up to the next even number of seconds.
voidsetUpdateMode(boolean update)
protected voidzipDir(PlexusIoResource dir, ZipOutputStream zOut, String vPath, int mode)
protected voidzipFile(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 voidzipFile(ArchiveEntry entry, ZipOutputStream zOut, String vPath)
Method that gets called when adding from java.io.File instances.

Field Detail

addedDirs

protected Hashtable addedDirs

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

doubleFilePass

protected boolean doubleFilePass

duplicate

protected String duplicate

Deprecated: Use setDuplicateBehavior instead.

entries

protected Hashtable entries

skipWriting

protected boolean skipWriting

Method Detail

addParentDirs

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

addResources

protected final void addResources(ResourceIterator resources, ZipOutputStream zOut)
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.

See Also: AbstractZipArchiver

close

protected void close()

createEmptyZip

protected boolean createEmptyZip(File zipFile)
Create an empty zip file

Returns: true for historic reasons

execute

protected void execute()

finalizeZipOutputStream

protected void finalizeZipOutputStream(ZipOutputStream zOut)

getArchiveType

protected String getArchiveType()

getComment

public String getComment()

getEncoding

public String getEncoding()

getZipEntryNames

protected Map getZipEntryNames(File file)

initZipOutputStream

protected void initZipOutputStream(ZipOutputStream zOut)
method for subclasses to override

isCompress

public boolean isCompress()

isFileAdded

protected boolean isFileAdded(ArchiveEntry entry, Map entries)

isFilesonly

public boolean isFilesonly()

isFileUpdated

protected boolean isFileUpdated(ArchiveEntry entry, Map entries)

isInUpdateMode

public boolean isInUpdateMode()

isRoundUp

public boolean isRoundUp()

isSupportingForced

public boolean isSupportingForced()
method for subclasses to override

reset

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

See Also: AbstractZipArchiver

revert

protected boolean revert(StringBuffer messageBuffer)

setComment

public void setComment(String comment)

setCompress

public void setCompress(boolean compress)

setEncoding

public void setEncoding(String encoding)

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(PlexusIoResource dir, ZipOutputStream zOut, String vPath, int mode)

zipFile

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.

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)
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

Copyright © 2001-2009 Codehaus. All Rights Reserved.