Class ZipEntry
- java.lang.Object
- 
- java.util.zip.ZipEntry
- 
- org.apache.tools.zip.ZipEntry
 
 
- 
- All Implemented Interfaces:
- java.lang.Cloneable
 
 public class ZipEntry extends java.util.zip.ZipEntry implements java.lang.CloneableExtension that adds better handling of extra fields and provides access to the internal and external file attributes.The extra data is expected to follow the recommendation of APPNOTE.txt: - the extra byte array consists of a sequence of extra fields
- each extra fields starts by a two byte header id followed by a two byte sequence holding the length of the remainder of data.
 Any extra data that cannot be parsed by the rules above will be consumed as "unparseable" extra data and treated differently by the methods of this class. Older versions would have thrown an exception if any attempt was made to read or write extra data not conforming to the recommendation. 
- 
- 
Field SummaryFields Modifier and Type Field Description static intCENATTstatic intCENATXstatic intCENCOMstatic intCENCRCstatic intCENDSKstatic intCENEXTstatic intCENFLGstatic intCENHDRstatic intCENHOWstatic intCENLENstatic intCENNAMstatic intCENOFFstatic longCENSIGstatic intCENSIZstatic intCENTIMstatic intCENVEMstatic intCENVERstatic intCRC_UNKNOWNstatic intENDCOMstatic intENDHDRstatic intENDOFFstatic longENDSIGstatic intENDSIZstatic intENDSUBstatic intENDTOTstatic intEXTCRCstatic intEXTHDRstatic intEXTLENstatic longEXTSIGstatic intEXTSIZstatic intLOCCRCstatic intLOCEXTstatic intLOCFLGstatic intLOCHDRstatic intLOCHOWstatic intLOCLENstatic intLOCNAMstatic longLOCSIGstatic intLOCSIZstatic intLOCTIMstatic intLOCVERstatic intPLATFORM_FATstatic intPLATFORM_UNIX
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedZipEntry()ZipEntry(java.io.File inputFile, java.lang.String entryName)Creates a new zip entry taking some information from the given file and using the provided name.ZipEntry(java.lang.String name)Creates a new zip entry with the specified name.ZipEntry(java.util.zip.ZipEntry entry)Creates a new zip entry with fields taken from the specified zip entry.ZipEntry(ZipEntry entry)Creates a new zip entry with fields taken from the specified zip entry.
 - 
Method SummaryModifier and Type Method Description voidaddAsFirstExtraField(ZipExtraField ze)Adds an extra field - replacing an already present extra field of the same type.voidaddExtraField(ZipExtraField ze)Adds an extra field - replacing an already present extra field of the same type.java.lang.Objectclone()Overwrite clone.booleanequals(java.lang.Object obj)byte[]getCentralDirectoryExtra()Retrieves the extra data for the central directory.longgetExternalAttributes()Retrieves the external file attributes.ZipExtraFieldgetExtraField(ZipShort type)Looks up an extra field by its header id.ZipExtraField[]getExtraFields()Retrieves all extra fields that have been parsed successfully.ZipExtraField[]getExtraFields(boolean includeUnparseable)Retrieves extra fields.GeneralPurposeBitgetGeneralPurposeBit()The "general purpose bit" field.intgetInternalAttributes()Retrieves the internal file attributes.java.util.DategetLastModifiedDate()byte[]getLocalFileDataExtra()Retrieves the extra data for the local file data.intgetMethod()Returns the compression method of this entry, or -1 if the compression method has not been specified.java.lang.StringgetName()Get the name of the entry.intgetPlatform()Platform specification to put into the "version made by" part of the central file header.byte[]getRawName()Returns the raw bytes that made up the name before it has been converted using the configured or guessed encoding.longgetSize()Gets the uncompressed size of the entry data.intgetUnixMode()Unix permission.UnparseableExtraFieldDatagetUnparseableExtraFieldData()Looks up extra field data that couldn't be parsed correctly.inthashCode()Get the hashCode of the entry.booleanisDirectory()Is this entry a directory?voidremoveExtraField(ZipShort type)Remove an extra field.voidremoveUnparseableExtraFieldData()Removes unparseable extra field data.voidsetCentralDirectoryExtra(byte[] b)Sets the central directory part of extra fields.voidsetComprSize(long size)Deprecated.since 1.7.voidsetExternalAttributes(long value)Sets the external file attributes.protected voidsetExtra()Unfortunatelyjava.util.zip.ZipOutputStreamseems to access the extra data directly, so overriding getExtra doesn't help - we need to modify super's data directly.voidsetExtra(byte[] extra)Parses the given bytes as extra field data and consumes any unparseable data as anUnparseableExtraFieldDatainstance.voidsetExtraFields(ZipExtraField[] fields)Replaces all currently attached extra fields with the new array.voidsetGeneralPurposeBit(GeneralPurposeBit b)The "general purpose bit" field.voidsetInternalAttributes(int value)Sets the internal file attributes.voidsetMethod(int method)Sets the compression method of this entry.protected voidsetName(java.lang.String name)Set the name of the entry.protected voidsetName(java.lang.String name, byte[] rawName)Sets the name using the raw bytes and the string created from it by guessing or using the configured encoding.protected voidsetPlatform(int platform)Set the platform (UNIX or FAT).voidsetSize(long size)Sets the uncompressed size of the entry data.voidsetUnixMode(int mode)Sets Unix permissions in a way that is understood by Info-Zip's unzip command.- 
Methods inherited from class java.util.zip.ZipEntrygetComment, getCompressedSize, getCrc, getCreationTime, getExtra, getLastAccessTime, getLastModifiedTime, getTime, getTimeLocal, setComment, setCompressedSize, setCrc, setCreationTime, setLastAccessTime, setLastModifiedTime, setTime, setTimeLocal, toString
 
- 
 
- 
- 
- 
Field Detail- 
PLATFORM_UNIXpublic static final int PLATFORM_UNIX - See Also:
- Constant Field Values
 
 - 
PLATFORM_FATpublic static final int PLATFORM_FAT - See Also:
- Constant Field Values
 
 - 
CRC_UNKNOWNpublic static final int CRC_UNKNOWN - See Also:
- Constant Field Values
 
 - 
LOCSIGpublic static final long LOCSIG - See Also:
- Constant Field Values
 
 - 
EXTSIGpublic static final long EXTSIG - See Also:
- Constant Field Values
 
 - 
CENSIGpublic static final long CENSIG - See Also:
- Constant Field Values
 
 - 
ENDSIGpublic static final long ENDSIG - See Also:
- Constant Field Values
 
 - 
LOCHDRpublic static final int LOCHDR - See Also:
- Constant Field Values
 
 - 
EXTHDRpublic static final int EXTHDR - See Also:
- Constant Field Values
 
 - 
CENHDRpublic static final int CENHDR - See Also:
- Constant Field Values
 
 - 
ENDHDRpublic static final int ENDHDR - See Also:
- Constant Field Values
 
 - 
LOCVERpublic static final int LOCVER - See Also:
- Constant Field Values
 
 - 
LOCFLGpublic static final int LOCFLG - See Also:
- Constant Field Values
 
 - 
LOCHOWpublic static final int LOCHOW - See Also:
- Constant Field Values
 
 - 
LOCTIMpublic static final int LOCTIM - See Also:
- Constant Field Values
 
 - 
LOCCRCpublic static final int LOCCRC - See Also:
- Constant Field Values
 
 - 
LOCSIZpublic static final int LOCSIZ - See Also:
- Constant Field Values
 
 - 
LOCLENpublic static final int LOCLEN - See Also:
- Constant Field Values
 
 - 
LOCNAMpublic static final int LOCNAM - See Also:
- Constant Field Values
 
 - 
LOCEXTpublic static final int LOCEXT - See Also:
- Constant Field Values
 
 - 
EXTCRCpublic static final int EXTCRC - See Also:
- Constant Field Values
 
 - 
EXTSIZpublic static final int EXTSIZ - See Also:
- Constant Field Values
 
 - 
EXTLENpublic static final int EXTLEN - See Also:
- Constant Field Values
 
 - 
CENVEMpublic static final int CENVEM - See Also:
- Constant Field Values
 
 - 
CENVERpublic static final int CENVER - See Also:
- Constant Field Values
 
 - 
CENFLGpublic static final int CENFLG - See Also:
- Constant Field Values
 
 - 
CENHOWpublic static final int CENHOW - See Also:
- Constant Field Values
 
 - 
CENTIMpublic static final int CENTIM - See Also:
- Constant Field Values
 
 - 
CENCRCpublic static final int CENCRC - See Also:
- Constant Field Values
 
 - 
CENSIZpublic static final int CENSIZ - See Also:
- Constant Field Values
 
 - 
CENLENpublic static final int CENLEN - See Also:
- Constant Field Values
 
 - 
CENNAMpublic static final int CENNAM - See Also:
- Constant Field Values
 
 - 
CENEXTpublic static final int CENEXT - See Also:
- Constant Field Values
 
 - 
CENCOMpublic static final int CENCOM - See Also:
- Constant Field Values
 
 - 
CENDSKpublic static final int CENDSK - See Also:
- Constant Field Values
 
 - 
CENATTpublic static final int CENATT - See Also:
- Constant Field Values
 
 - 
CENATXpublic static final int CENATX - See Also:
- Constant Field Values
 
 - 
CENOFFpublic static final int CENOFF - See Also:
- Constant Field Values
 
 - 
ENDSUBpublic static final int ENDSUB - See Also:
- Constant Field Values
 
 - 
ENDTOTpublic static final int ENDTOT - See Also:
- Constant Field Values
 
 - 
ENDSIZpublic static final int ENDSIZ - See Also:
- Constant Field Values
 
 - 
ENDOFFpublic static final int ENDOFF - See Also:
- Constant Field Values
 
 - 
ENDCOMpublic static final int ENDCOM - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
ZipEntrypublic ZipEntry(java.lang.String name) Creates a new zip entry with the specified name.Assumes the entry represents a directory if and only if the name ends with a forward slash "/". - Parameters:
- name- the name of the entry
- Since:
- 1.1
 
 - 
ZipEntrypublic ZipEntry(java.util.zip.ZipEntry entry) throws java.util.zip.ZipExceptionCreates a new zip entry with fields taken from the specified zip entry.Assumes the entry represents a directory if and only if the name ends with a forward slash "/". - Parameters:
- entry- the entry to get fields from
- Throws:
- java.util.zip.ZipException- on error
- Since:
- 1.1
 
 - 
ZipEntrypublic ZipEntry(ZipEntry entry) throws java.util.zip.ZipException Creates a new zip entry with fields taken from the specified zip entry.Assumes the entry represents a directory if and only if the name ends with a forward slash "/". - Parameters:
- entry- the entry to get fields from
- Throws:
- java.util.zip.ZipException- on error
- Since:
- 1.1
 
 - 
ZipEntryprotected ZipEntry() - Since:
- 1.9
 
 - 
ZipEntrypublic ZipEntry(java.io.File inputFile, java.lang.String entryName)Creates a new zip entry taking some information from the given file and using the provided name.The name will be adjusted to end with a forward slash "/" if the file is a directory. If the file is not a directory a potential trailing forward slash will be stripped from the entry name. - Parameters:
- inputFile- File
- entryName- String
 
 
- 
 - 
Method Detail- 
clonepublic java.lang.Object clone() Overwrite clone.- Overrides:
- clonein class- java.util.zip.ZipEntry
- Returns:
- a cloned copy of this ZipEntry
- Since:
- 1.1
 
 - 
getMethodpublic int getMethod() Returns the compression method of this entry, or -1 if the compression method has not been specified.- Overrides:
- getMethodin class- java.util.zip.ZipEntry
- Returns:
- compression method
 
 - 
setMethodpublic void setMethod(int method) Sets the compression method of this entry.- Overrides:
- setMethodin class- java.util.zip.ZipEntry
- Parameters:
- method- compression method
 
 - 
getInternalAttributespublic int getInternalAttributes() Retrieves the internal file attributes.- Returns:
- the internal file attributes
- Since:
- 1.1
 
 - 
setInternalAttributespublic void setInternalAttributes(int value) Sets the internal file attributes.- Parameters:
- value- an- intvalue
- Since:
- 1.1
 
 - 
getExternalAttributespublic long getExternalAttributes() Retrieves the external file attributes.- Returns:
- the external file attributes
- Since:
- 1.1
 
 - 
setExternalAttributespublic void setExternalAttributes(long value) Sets the external file attributes.- Parameters:
- value- an- longvalue
- Since:
- 1.1
 
 - 
setUnixModepublic void setUnixMode(int mode) Sets Unix permissions in a way that is understood by Info-Zip's unzip command.- Parameters:
- mode- an- intvalue
- Since:
- Ant 1.5.2
 
 - 
getUnixModepublic int getUnixMode() Unix permission.- Returns:
- the unix permissions
- Since:
- Ant 1.6
 
 - 
getPlatformpublic int getPlatform() Platform specification to put into the "version made by" part of the central file header.- Returns:
- PLATFORM_FAT unless setUnixModehas been called, in which case PLATFORM_UNIX will be returned.
- Since:
- Ant 1.5.2
 
 - 
setPlatformprotected void setPlatform(int platform) Set the platform (UNIX or FAT).- Parameters:
- platform- an- intvalue - 0 is FAT, 3 is UNIX
- Since:
- 1.9
 
 - 
setExtraFieldspublic void setExtraFields(ZipExtraField[] fields) Replaces all currently attached extra fields with the new array.- Parameters:
- fields- an array of extra fields
- Since:
- 1.1
 
 - 
getExtraFieldspublic ZipExtraField[] getExtraFields() Retrieves all extra fields that have been parsed successfully.- Returns:
- an array of the extra fields
 
 - 
getExtraFieldspublic ZipExtraField[] getExtraFields(boolean includeUnparseable) Retrieves extra fields.- Parameters:
- includeUnparseable- whether to also return unparseable extra fields as- UnparseableExtraFieldDataif such data exists.
- Returns:
- an array of the extra fields
- Since:
- 1.1
 
 - 
addExtraFieldpublic void addExtraField(ZipExtraField ze) Adds an extra field - replacing an already present extra field of the same type.If no extra field of the same type exists, the field will be added as last field. - Parameters:
- ze- an extra field
- Since:
- 1.1
 
 - 
addAsFirstExtraFieldpublic void addAsFirstExtraField(ZipExtraField ze) Adds an extra field - replacing an already present extra field of the same type.The new extra field will be the first one. - Parameters:
- ze- an extra field
- Since:
- 1.1
 
 - 
removeExtraFieldpublic void removeExtraField(ZipShort type) Remove an extra field.- Parameters:
- type- the type of extra field to remove
- Since:
- 1.1
 
 - 
removeUnparseableExtraFieldDatapublic void removeUnparseableExtraFieldData() Removes unparseable extra field data.
 - 
getExtraFieldpublic ZipExtraField getExtraField(ZipShort type) Looks up an extra field by its header id.- Parameters:
- type- ZipShort
- Returns:
- null if no such field exists.
 
 - 
getUnparseableExtraFieldDatapublic UnparseableExtraFieldData getUnparseableExtraFieldData() Looks up extra field data that couldn't be parsed correctly.- Returns:
- null if no such field exists.
 
 - 
setExtrapublic void setExtra(byte[] extra) throws java.lang.RuntimeExceptionParses the given bytes as extra field data and consumes any unparseable data as anUnparseableExtraFieldDatainstance.- Overrides:
- setExtrain class- java.util.zip.ZipEntry
- Parameters:
- extra- an array of bytes to be parsed into extra fields
- Throws:
- java.lang.RuntimeException- if the bytes cannot be parsed
- java.lang.RuntimeException- on error
- Since:
- 1.1
 
 - 
setExtraprotected void setExtra() Unfortunatelyjava.util.zip.ZipOutputStreamseems to access the extra data directly, so overriding getExtra doesn't help - we need to modify super's data directly.- Since:
- 1.1
 
 - 
setCentralDirectoryExtrapublic void setCentralDirectoryExtra(byte[] b) Sets the central directory part of extra fields.- Parameters:
- b- boolean
 
 - 
getLocalFileDataExtrapublic byte[] getLocalFileDataExtra() Retrieves the extra data for the local file data.- Returns:
- the extra data for local file
- Since:
- 1.1
 
 - 
getCentralDirectoryExtrapublic byte[] getCentralDirectoryExtra() Retrieves the extra data for the central directory.- Returns:
- the central directory extra data
- Since:
- 1.1
 
 - 
setComprSize@Deprecated public void setComprSize(long size) Deprecated.since 1.7. Use setCompressedSize directly.Make this class work in JDK 1.1 like a 1.2 class.This either stores the size for later usage or invokes setCompressedSize via reflection. - Parameters:
- size- the size to use
- Since:
- 1.2
 
 - 
getNamepublic java.lang.String getName() Get the name of the entry.- Overrides:
- getNamein class- java.util.zip.ZipEntry
- Returns:
- the entry name
- Since:
- 1.9
 
 - 
isDirectorypublic boolean isDirectory() Is this entry a directory?- Overrides:
- isDirectoryin class- java.util.zip.ZipEntry
- Returns:
- true if the entry is a directory
- Since:
- 1.10
 
 - 
setNameprotected void setName(java.lang.String name) Set the name of the entry.- Parameters:
- name- the name to use
 
 - 
getSizepublic long getSize() Gets the uncompressed size of the entry data.- Overrides:
- getSizein class- java.util.zip.ZipEntry
- Returns:
- the entry size
 
 - 
setSizepublic void setSize(long size) Sets the uncompressed size of the entry data.- Overrides:
- setSizein class- java.util.zip.ZipEntry
- Parameters:
- size- the uncompressed size in bytes
- Throws:
- java.lang.IllegalArgumentException- if the specified size is less than 0
 
 - 
setNameprotected void setName(java.lang.String name, byte[] rawName)Sets the name using the raw bytes and the string created from it by guessing or using the configured encoding.- Parameters:
- name- the name to use created from the raw bytes using the guessed or configured encoding
- rawName- the bytes originally read as name from the archive
 
 - 
getRawNamepublic byte[] getRawName() Returns the raw bytes that made up the name before it has been converted using the configured or guessed encoding.This method will return null if this instance has not been read from an archive. - Returns:
- byte[]
 
 - 
hashCodepublic int hashCode() Get the hashCode of the entry. This uses the name as the hashcode.- Overrides:
- hashCodein class- java.util.zip.ZipEntry
- Returns:
- a hashcode.
- Since:
- Ant 1.7
 
 - 
getGeneralPurposeBitpublic GeneralPurposeBit getGeneralPurposeBit() The "general purpose bit" field.- Returns:
- GeneralPurposeBit
 
 - 
setGeneralPurposeBitpublic void setGeneralPurposeBit(GeneralPurposeBit b) The "general purpose bit" field.- Parameters:
- b- GeneralPurposeBit
 
 - 
getLastModifiedDatepublic java.util.Date getLastModifiedDate() 
 - 
equalspublic boolean equals(java.lang.Object obj) - Overrides:
- equalsin class- java.lang.Object
 
 
- 
 
-