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 Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ModifierConstructorDescriptionprotected
ZipEntry()
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 Summary
Modifier and TypeMethodDescriptionvoid
Adds an extra field - replacing an already present extra field of the same type.void
Adds an extra field - replacing an already present extra field of the same type.clone()
Override clone.boolean
byte[]
Retrieves the extra data for the central directory.long
Retrieves 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.int
Retrieves the internal file attributes.Get last modified time asDate
.byte[]
Retrieves the extra data for the local file data.int
Returns the compression method of this entry, or -1 if the compression method has not been specified.getName()
Get the name of the entry.int
Platform 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.long
getSize()
Gets the uncompressed size of the entry data.int
Unix permission.Looks up extra field data that couldn't be parsed correctly.int
hashCode()
Get the hashCode of the entry.boolean
Is this entry a directory?void
removeExtraField
(ZipShort type) Remove an extra field.void
Removes unparseable extra field data.void
setCentralDirectoryExtra
(byte[] b) Sets the central directory part of extra fields.void
setComprSize
(long size) Deprecated.since 1.7.void
setExternalAttributes
(long value) Sets the external file attributes.protected void
setExtra()
Unfortunatelyjava.util.zip.ZipOutputStream
seems to access the extra data directly, so overriding getExtra doesn't help - we need to modify super's data directly.void
setExtra
(byte[] extra) Parses the given bytes as extra field data and consumes any unparseable data as anUnparseableExtraFieldData
instance.void
setExtraFields
(ZipExtraField[] fields) Replaces all currently attached extra fields with the new array.void
The "general purpose bit" field.void
setInternalAttributes
(int value) Sets the internal file attributes.void
setMethod
(int method) Sets the compression method of this entry.protected void
Set the name of the entry.protected void
Sets the name using the raw bytes and the string created from it by guessing or using the configured encoding.protected void
setPlatform
(int platform) Set the platform (UNIX or FAT).void
setSize
(long size) Sets the uncompressed size of the entry data.void
setUnixMode
(int mode) Sets Unix permissions in a way that is understood by Info-Zip's unzip command.Methods inherited from class java.util.zip.ZipEntry
getComment, getCompressedSize, getCrc, getCreationTime, getExtra, getLastAccessTime, getLastModifiedTime, getTime, getTimeLocal, setComment, setCompressedSize, setCrc, setCreationTime, setLastAccessTime, setLastModifiedTime, setTime, setTimeLocal, toString
-
Field Details
-
PLATFORM_UNIX
public static final int PLATFORM_UNIX- See Also:
-
PLATFORM_FAT
public static final int PLATFORM_FAT- See Also:
-
CRC_UNKNOWN
public static final int CRC_UNKNOWN- See Also:
-
LOCSIG
static final long LOCSIG- See Also:
-
EXTSIG
static final long EXTSIG- See Also:
-
CENSIG
static final long CENSIG- See Also:
-
ENDSIG
static final long ENDSIG- See Also:
-
LOCHDR
static final int LOCHDR- See Also:
-
EXTHDR
static final int EXTHDR- See Also:
-
CENHDR
static final int CENHDR- See Also:
-
ENDHDR
static final int ENDHDR- See Also:
-
LOCVER
static final int LOCVER- See Also:
-
LOCFLG
static final int LOCFLG- See Also:
-
LOCHOW
static final int LOCHOW- See Also:
-
LOCTIM
static final int LOCTIM- See Also:
-
LOCCRC
static final int LOCCRC- See Also:
-
LOCSIZ
static final int LOCSIZ- See Also:
-
LOCLEN
static final int LOCLEN- See Also:
-
LOCNAM
static final int LOCNAM- See Also:
-
LOCEXT
static final int LOCEXT- See Also:
-
EXTCRC
static final int EXTCRC- See Also:
-
EXTSIZ
static final int EXTSIZ- See Also:
-
EXTLEN
static final int EXTLEN- See Also:
-
CENVEM
static final int CENVEM- See Also:
-
CENVER
static final int CENVER- See Also:
-
CENFLG
static final int CENFLG- See Also:
-
CENHOW
static final int CENHOW- See Also:
-
CENTIM
static final int CENTIM- See Also:
-
CENCRC
static final int CENCRC- See Also:
-
CENSIZ
static final int CENSIZ- See Also:
-
CENLEN
static final int CENLEN- See Also:
-
CENNAM
static final int CENNAM- See Also:
-
CENEXT
static final int CENEXT- See Also:
-
CENCOM
static final int CENCOM- See Also:
-
CENDSK
static final int CENDSK- See Also:
-
CENATT
static final int CENATT- See Also:
-
CENATX
static final int CENATX- See Also:
-
CENOFF
static final int CENOFF- See Also:
-
ENDSUB
static final int ENDSUB- See Also:
-
ENDTOT
static final int ENDTOT- See Also:
-
ENDSIZ
static final int ENDSIZ- See Also:
-
ENDOFF
static final int ENDOFF- See Also:
-
ENDCOM
static final int ENDCOM- See Also:
-
-
Constructor Details
-
ZipEntry
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
-
ZipEntry
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:
ZipException
- on error- Since:
- 1.1
-
ZipEntry
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:
ZipException
- on error- Since:
- 1.1
-
ZipEntry
protected ZipEntry()- Since:
- 1.9
-
ZipEntry
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
- FileentryName
- String
-
-
Method Details
-
clone
Override clone. -
getMethod
public int getMethod()Returns the compression method of this entry, or -1 if the compression method has not been specified. -
setMethod
public void setMethod(int method) Sets the compression method of this entry. -
getInternalAttributes
public int getInternalAttributes()Retrieves the internal file attributes.- Returns:
- the internal file attributes
- Since:
- 1.1
-
setInternalAttributes
public void setInternalAttributes(int value) Sets the internal file attributes.- Parameters:
value
- anint
value- Since:
- 1.1
-
getExternalAttributes
public long getExternalAttributes()Retrieves the external file attributes.- Returns:
- the external file attributes
- Since:
- 1.1
-
setExternalAttributes
public void setExternalAttributes(long value) Sets the external file attributes.- Parameters:
value
- anlong
value- Since:
- 1.1
-
setUnixMode
public void setUnixMode(int mode) Sets Unix permissions in a way that is understood by Info-Zip's unzip command.- Parameters:
mode
- anint
value- Since:
- Ant 1.5.2
-
getUnixMode
public int getUnixMode()Unix permission.- Returns:
- the unix permissions
- Since:
- Ant 1.6
-
getPlatform
public int getPlatform()Platform specification to put into the "version made by" part of the central file header.- Returns:
- PLATFORM_FAT unless
setUnixMode
has been called, in which case PLATFORM_UNIX will be returned. - Since:
- Ant 1.5.2
-
setPlatform
protected void setPlatform(int platform) Set the platform (UNIX or FAT).- Parameters:
platform
- anint
value - 0 is FAT, 3 is UNIX- Since:
- 1.9
-
setExtraFields
Replaces all currently attached extra fields with the new array.- Parameters:
fields
- an array of extra fields- Since:
- 1.1
-
getExtraFields
Retrieves all extra fields that have been parsed successfully.- Returns:
- an array of the extra fields
-
getExtraFields
Retrieves extra fields.- Parameters:
includeUnparseable
- whether to also return unparseable extra fields asUnparseableExtraFieldData
if such data exists.- Returns:
- an array of the extra fields
- Since:
- 1.1
-
addExtraField
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
-
addAsFirstExtraField
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
-
removeExtraField
Remove an extra field.- Parameters:
type
- the type of extra field to remove- Since:
- 1.1
-
removeUnparseableExtraFieldData
public void removeUnparseableExtraFieldData()Removes unparseable extra field data. -
getExtraField
Looks up an extra field by its header id.- Parameters:
type
- ZipShort- Returns:
null
if no such field exists.
-
getUnparseableExtraFieldData
Looks up extra field data that couldn't be parsed correctly.- Returns:
null
if no such field exists.
-
setExtra
Parses the given bytes as extra field data and consumes any unparseable data as anUnparseableExtraFieldData
instance.- Overrides:
setExtra
in classZipEntry
- Parameters:
extra
- an array of bytes to be parsed into extra fields- Throws:
RuntimeException
- if the bytes cannot be parsedRuntimeException
- on error- Since:
- 1.1
-
setExtra
protected void setExtra()Unfortunatelyjava.util.zip.ZipOutputStream
seems to access the extra data directly, so overriding getExtra doesn't help - we need to modify super's data directly.- Since:
- 1.1
-
setCentralDirectoryExtra
public void setCentralDirectoryExtra(byte[] b) Sets the central directory part of extra fields.- Parameters:
b
-boolean
-
getLocalFileDataExtra
public byte[] getLocalFileDataExtra()Retrieves the extra data for the local file data.- Returns:
- the extra data for local file
- Since:
- 1.1
-
getCentralDirectoryExtra
public byte[] getCentralDirectoryExtra()Retrieves the extra data for the central directory.- Returns:
- the central directory extra data
- Since:
- 1.1
-
setComprSize
Deprecated.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
-
getName
Get the name of the entry. -
isDirectory
public boolean isDirectory()Is this entry a directory?- Overrides:
isDirectory
in classZipEntry
- Returns:
true
if the entry is a directory- Since:
- 1.10
-
setName
Set the name of the entry.- Parameters:
name
- the name to use
-
getSize
public long getSize()Gets the uncompressed size of the entry data. -
setSize
public void setSize(long size) Sets the uncompressed size of the entry data.- Overrides:
setSize
in classZipEntry
- Parameters:
size
- the uncompressed size in bytes- Throws:
IllegalArgumentException
- if the specified size is less than 0
-
setName
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 encodingrawName
- the bytes originally read as name from the archive
-
getRawName
public 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[]
-
hashCode
public int hashCode()Get the hashCode of the entry. This uses the name as the hashcode. -
getGeneralPurposeBit
The "general purpose bit" field.- Returns:
- GeneralPurposeBit
-
setGeneralPurposeBit
The "general purpose bit" field.- Parameters:
b
- GeneralPurposeBit
-
getLastModifiedDate
Get last modified time asDate
.- Returns:
Date
-
equals
-