public class ZipEntry extends java.util.zip.ZipEntry implements Cloneable
The extra data is expected to follow the recommendation of APPNOTE.txt:
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.
Modifier and Type | Field and Description |
---|---|
static int |
CENATT |
static int |
CENATX |
static int |
CENCOM |
static int |
CENCRC |
static int |
CENDSK |
static int |
CENEXT |
static int |
CENFLG |
static int |
CENHDR |
static int |
CENHOW |
static int |
CENLEN |
static int |
CENNAM |
static int |
CENOFF |
static long |
CENSIG |
static int |
CENSIZ |
static int |
CENTIM |
static int |
CENVEM |
static int |
CENVER |
static int |
CRC_UNKNOWN |
static int |
ENDCOM |
static int |
ENDHDR |
static int |
ENDOFF |
static long |
ENDSIG |
static int |
ENDSIZ |
static int |
ENDSUB |
static int |
ENDTOT |
static int |
EXTCRC |
static int |
EXTHDR |
static int |
EXTLEN |
static long |
EXTSIG |
static int |
EXTSIZ |
static int |
LOCCRC |
static int |
LOCEXT |
static int |
LOCFLG |
static int |
LOCHDR |
static int |
LOCHOW |
static int |
LOCLEN |
static int |
LOCNAM |
static long |
LOCSIG |
static int |
LOCSIZ |
static int |
LOCTIM |
static int |
LOCVER |
static int |
PLATFORM_FAT |
static int |
PLATFORM_UNIX |
Modifier | Constructor and Description |
---|---|
protected |
ZipEntry() |
|
ZipEntry(File inputFile,
String entryName)
Creates a new zip entry taking some information from the given
file and using the provided name.
|
|
ZipEntry(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.
|
Modifier and Type | Method and Description |
---|---|
void |
addAsFirstExtraField(ZipExtraField ze)
Adds an extra field - replacing an already present extra field
of the same type.
|
void |
addExtraField(ZipExtraField ze)
Adds an extra field - replacing an already present extra field
of the same type.
|
Object |
clone()
Overwrite clone.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
byte[] |
getCentralDirectoryExtra()
Retrieves the extra data for the central directory.
|
long |
getExternalAttributes()
Retrieves the external file attributes.
|
ZipExtraField |
getExtraField(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.
|
GeneralPurposeBit |
getGeneralPurposeBit()
The "general purpose bit" field.
|
int |
getInternalAttributes()
Retrieves the internal file attributes.
|
Date |
getLastModifiedDate() |
byte[] |
getLocalFileDataExtra()
Retrieves the extra data for the local file data.
|
int |
getMethod()
Returns the compression method of this entry, or -1 if the
compression method has not been specified.
|
String |
getName()
Get the name of the entry.
|
int |
getPlatform()
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.
|
long |
getSize()
Gets the uncompressed size of the entry data.
|
int |
getUnixMode()
Unix permission.
|
UnparseableExtraFieldData |
getUnparseableExtraFieldData()
Looks up extra field data that couldn't be parsed correctly.
|
int |
hashCode()
Get the hashCode of the entry.
|
boolean |
isDirectory()
Is this entry a directory?
|
void |
removeExtraField(ZipShort type)
Remove an extra field.
|
void |
removeUnparseableExtraFieldData()
Removes unparseable extra field data.
|
void |
setCentralDirectoryExtra(byte[] b)
Sets the central directory part of extra fields.
|
void |
setExternalAttributes(long value)
Sets the external file attributes.
|
protected void |
setExtra()
Unfortunately
java.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 an
UnparseableExtraFieldData
instance. |
void |
setExtraFields(ZipExtraField[] fields)
Replaces all currently attached extra fields with the new array.
|
void |
setGeneralPurposeBit(GeneralPurposeBit b)
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 |
setName(String name)
Set the name of the entry.
|
protected void |
setName(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 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.
|
public static final int CRC_UNKNOWN
public static final int PLATFORM_FAT
public static final int PLATFORM_UNIX
public static final int CENATT
public static final int CENATX
public static final int CENCOM
public static final int CENCRC
public static final int CENDSK
public static final int CENEXT
public static final int CENFLG
public static final int CENHDR
public static final int CENHOW
public static final int CENLEN
public static final int CENNAM
public static final int CENOFF
public static final long CENSIG
public static final int CENSIZ
public static final int CENTIM
public static final int CENVEM
public static final int CENVER
public static final int ENDCOM
public static final int ENDHDR
public static final int ENDOFF
public static final long ENDSIG
public static final int ENDSIZ
public static final int ENDSUB
public static final int ENDTOT
public static final int EXTCRC
public static final int EXTHDR
public static final int EXTLEN
public static final long EXTSIG
public static final int EXTSIZ
public static final int LOCCRC
public static final int LOCEXT
public static final int LOCFLG
public static final int LOCHDR
public static final int LOCHOW
public static final int LOCLEN
public static final int LOCNAM
public static final long LOCSIG
public static final int LOCSIZ
public static final int LOCTIM
public static final int LOCVER
protected ZipEntry()
public ZipEntry(File inputFile, String entryName)
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.
public ZipEntry(String name)
Assumes the entry represents a directory if and only if the name ends with a forward slash "/".
name
- the name of the entrypublic ZipEntry(java.util.zip.ZipEntry entry) throws java.util.zip.ZipException
Assumes the entry represents a directory if and only if the name ends with a forward slash "/".
entry
- the entry to get fields fromjava.util.zip.ZipException
- on errorpublic ZipEntry(ZipEntry entry) throws java.util.zip.ZipException
Assumes the entry represents a directory if and only if the name ends with a forward slash "/".
entry
- the entry to get fields fromjava.util.zip.ZipException
- on errorpublic void addAsFirstExtraField(ZipExtraField ze)
The new extra field will be the first one.
ze
- an extra fieldpublic void addExtraField(ZipExtraField ze)
If no extra field of the same type exists, the field will be added as last field.
ze
- an extra fieldpublic Object clone()
clone
in class java.util.zip.ZipEntry
Cloneable
public boolean equals(Object obj)
Object
The equals
method implements an equivalence relation on non-null object references:
x
, x.equals(x)
should return true
.
x
and y
,
x.equals(y)
should return true
if and only if y.equals(x)
returns
true
.
x
, y
, and
z
, if x.equals(y)
returns true
and y.equals(z)
returns
true
, then x.equals(z)
should return true
.
x
and y
, multiple
invocations of x.equals(y)
consistently return true
or consistently return
false
, provided no information used in equals
comparisons on the objects is
modified.
x
, x.equals(null)
should return
false
.
The equals
method for class Object
implements the most discriminating possible
equivalence relation on objects; that is, for any non-null reference values x
and
y
, this method returns true
if and only if x
and y
refer to the
same object (x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method
is overridden, so as to maintain the general contract for the hashCode
method, which
states that equal objects must have equal hash codes.
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj argument; false
otherwise.Object.hashCode()
,
HashMap
public byte[] getCentralDirectoryExtra()
public long getExternalAttributes()
public ZipExtraField getExtraField(ZipShort type)
public ZipExtraField[] getExtraFields()
public ZipExtraField[] getExtraFields(boolean includeUnparseable)
includeUnparseable
- whether to also return unparseable
extra fields as UnparseableExtraFieldData
if such data
exists.public GeneralPurposeBit getGeneralPurposeBit()
public int getInternalAttributes()
public Date getLastModifiedDate()
public byte[] getLocalFileDataExtra()
public int getMethod()
getMethod
in class java.util.zip.ZipEntry
public String getName()
getName
in class java.util.zip.ZipEntry
public int getPlatform()
setUnixMode
has been called, in which case PLATFORM_UNIX will be returned.public byte[] getRawName()
This method will return null if this instance has not been read from an archive.
public long getSize()
getSize
in class java.util.zip.ZipEntry
public int getUnixMode()
public UnparseableExtraFieldData getUnparseableExtraFieldData()
public int hashCode()
hashCode
in class java.util.zip.ZipEntry
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
public boolean isDirectory()
isDirectory
in class java.util.zip.ZipEntry
public void removeExtraField(ZipShort type)
type
- the type of extra field to removepublic void removeUnparseableExtraFieldData()
public void setCentralDirectoryExtra(byte[] b)
public void setExternalAttributes(long value)
value
- an long
valueprotected void setExtra()
java.util.zip.ZipOutputStream
seems to access the extra data
directly, so overriding getExtra doesn't help - we need to
modify super's data directly.public void setExtra(byte[] extra) throws RuntimeException
UnparseableExtraFieldData
instance.setExtra
in class java.util.zip.ZipEntry
extra
- an array of bytes to be parsed into extra fieldsRuntimeException
- if the bytes cannot be parsedRuntimeException
- on errorpublic void setExtraFields(ZipExtraField[] fields)
fields
- an array of extra fieldspublic void setGeneralPurposeBit(GeneralPurposeBit b)
public void setInternalAttributes(int value)
value
- an int
valuepublic void setMethod(int method)
setMethod
in class java.util.zip.ZipEntry
method
- compression methodprotected void setName(String name)
name
- the name to useprotected void setName(String name, byte[] rawName)
name
- the name to use created from the raw bytes using
the guessed or configured encodingrawName
- the bytes originally read as name from the
archiveprotected void setPlatform(int platform)
platform
- an int
value - 0 is FAT, 3 is UNIXpublic void setSize(long size)
setSize
in class java.util.zip.ZipEntry
size
- the uncompressed size in bytesIllegalArgumentException
- if the specified size is less
than 0public void setUnixMode(int mode)
mode
- an int
value