Class ZipEntry
- All Implemented Interfaces:
- Cloneable
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 SummaryFieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final longstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final longstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final longstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final longstatic final intstatic final intstatic final intstatic final intstatic final int
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedZipEntry()Creates a new zip entry taking some information from the given file and using the provided name.Creates a new zip entry with the specified name.Creates a new zip entry with fields taken from the specified zip entry.Creates a new zip entry with fields taken from the specified zip entry.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds an extra field - replacing an already present extra field of the same type.voidAdds an extra field - replacing an already present extra field of the same type.clone()Override clone.booleanbyte[]Retrieves the extra data for the central directory.longRetrieves the external file attributes.getExtraField(ZipShort type) Looks up an extra field by its header id.Retrieves all extra fields that have been parsed successfully.getExtraFields(boolean includeUnparseable) Retrieves extra fields.The "general purpose bit" field.intRetrieves the internal file attributes.Get last modified time asDate.byte[]Retrieves the extra data for the local file data.intReturns the compression method of this entry, or -1 if the compression method has not been specified.getName()Get the name of the entry.intPlatform specification to put into the "version made by" part of the central file header.byte[]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.intUnix permission.Looks up extra field data that couldn't be parsed correctly.inthashCode()Get the hashCode of the entry.booleanIs this entry a directory?voidremoveExtraField(ZipShort type) Remove an extra field.voidRemoves 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.voidThe "general purpose bit" field.voidsetInternalAttributes(int value) Sets the internal file attributes.voidsetMethod(int method) Sets the compression method of this entry.protected voidSet the name of the entry.protected voidSets 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 Details- 
PLATFORM_UNIXpublic static final int PLATFORM_UNIX- See Also:
 
- 
PLATFORM_FATpublic static final int PLATFORM_FAT- See Also:
 
- 
CRC_UNKNOWNpublic static final int CRC_UNKNOWN- See Also:
 
- 
LOCSIGstatic final long LOCSIG- See Also:
 
- 
EXTSIGstatic final long EXTSIG- See Also:
 
- 
CENSIGstatic final long CENSIG- See Also:
 
- 
ENDSIGstatic final long ENDSIG- See Also:
 
- 
LOCHDRstatic final int LOCHDR- See Also:
 
- 
EXTHDRstatic final int EXTHDR- See Also:
 
- 
CENHDRstatic final int CENHDR- See Also:
 
- 
ENDHDRstatic final int ENDHDR- See Also:
 
- 
LOCVERstatic final int LOCVER- See Also:
 
- 
LOCFLGstatic final int LOCFLG- See Also:
 
- 
LOCHOWstatic final int LOCHOW- See Also:
 
- 
LOCTIMstatic final int LOCTIM- See Also:
 
- 
LOCCRCstatic final int LOCCRC- See Also:
 
- 
LOCSIZstatic final int LOCSIZ- See Also:
 
- 
LOCLENstatic final int LOCLEN- See Also:
 
- 
LOCNAMstatic final int LOCNAM- See Also:
 
- 
LOCEXTstatic final int LOCEXT- See Also:
 
- 
EXTCRCstatic final int EXTCRC- See Also:
 
- 
EXTSIZstatic final int EXTSIZ- See Also:
 
- 
EXTLENstatic final int EXTLEN- See Also:
 
- 
CENVEMstatic final int CENVEM- See Also:
 
- 
CENVERstatic final int CENVER- See Also:
 
- 
CENFLGstatic final int CENFLG- See Also:
 
- 
CENHOWstatic final int CENHOW- See Also:
 
- 
CENTIMstatic final int CENTIM- See Also:
 
- 
CENCRCstatic final int CENCRC- See Also:
 
- 
CENSIZstatic final int CENSIZ- See Also:
 
- 
CENLENstatic final int CENLEN- See Also:
 
- 
CENNAMstatic final int CENNAM- See Also:
 
- 
CENEXTstatic final int CENEXT- See Also:
 
- 
CENCOMstatic final int CENCOM- See Also:
 
- 
CENDSKstatic final int CENDSK- See Also:
 
- 
CENATTstatic final int CENATT- See Also:
 
- 
CENATXstatic final int CENATX- See Also:
 
- 
CENOFFstatic final int CENOFF- See Also:
 
- 
ENDSUBstatic final int ENDSUB- See Also:
 
- 
ENDTOTstatic final int ENDTOT- See Also:
 
- 
ENDSIZstatic final int ENDSIZ- See Also:
 
- 
ENDOFFstatic final int ENDOFF- See Also:
 
- 
ENDCOMstatic final int ENDCOM- See Also:
 
 
- 
- 
Constructor Details- 
ZipEntryCreates 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
 
- 
ZipEntryCreates 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:
- ZipException- on error
- Since:
- 1.1
 
- 
ZipEntryCreates 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:
- ZipException- on error
- Since:
- 1.1
 
- 
ZipEntryprotected ZipEntry()- Since:
- 1.9
 
- 
ZipEntryCreates 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 Details- 
cloneOverride clone.
- 
getMethodpublic int getMethod()Returns the compression method of this entry, or -1 if the compression method has not been specified.
- 
setMethodpublic void setMethod(int method) Sets the compression method of this entry.
- 
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
 
- 
setExtraFieldsReplaces all currently attached extra fields with the new array.- Parameters:
- fields- an array of extra fields
- Since:
- 1.1
 
- 
getExtraFieldsRetrieves all extra fields that have been parsed successfully.- Returns:
- an array of the extra fields
 
- 
getExtraFieldsRetrieves 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
 
- 
addExtraFieldAdds 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
 
- 
addAsFirstExtraFieldAdds 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
 
- 
removeExtraFieldRemove an extra field.- Parameters:
- type- the type of extra field to remove
- Since:
- 1.1
 
- 
removeUnparseableExtraFieldDatapublic void removeUnparseableExtraFieldData()Removes unparseable extra field data.
- 
getExtraFieldLooks up an extra field by its header id.- Parameters:
- type- ZipShort
- Returns:
- nullif no such field exists.
 
- 
getUnparseableExtraFieldDataLooks up extra field data that couldn't be parsed correctly.- Returns:
- nullif no such field exists.
 
- 
setExtraParses the given bytes as extra field data and consumes any unparseable data as anUnparseableExtraFieldDatainstance.- Overrides:
- setExtrain class- ZipEntry
- Parameters:
- extra- an array of bytes to be parsed into extra fields
- Throws:
- RuntimeException- if the bytes cannot be parsed
- 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
 
- 
setComprSizeDeprecated.since 1.7. UseZipEntry.setCompressedSize(long)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
 
- 
getNameGet the name of the entry.
- 
isDirectorypublic boolean isDirectory()Is this entry a directory?- Overrides:
- isDirectoryin class- ZipEntry
- Returns:
- trueif the entry is a directory
- Since:
- 1.10
 
- 
setNameSet the name of the entry.- Parameters:
- name- the name to use
 
- 
getSizepublic long getSize()Gets the uncompressed size of the entry data.
- 
setSizepublic void setSize(long size) Sets the uncompressed size of the entry data.- Overrides:
- setSizein class- ZipEntry
- Parameters:
- size- the uncompressed size in bytes
- Throws:
- IllegalArgumentException- if the specified size is less than 0
 
- 
setNameSets 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.
- 
getGeneralPurposeBitThe "general purpose bit" field.- Returns:
- GeneralPurposeBit
 
- 
setGeneralPurposeBitThe "general purpose bit" field.- Parameters:
- b- GeneralPurposeBit
 
- 
getLastModifiedDateGet last modified time asDate.- Returns:
- Date
 
- 
equals
 
-