public class ZipArchiveEntry extends java.util.zip.ZipEntry implements ArchiveEntry, EntryStreamOffsets
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. Versions prior to Apache Commons Compress 1.1 would have thrown an exception if any attempt was made to read or write extra data not conforming to the recommendation.
Modifier and Type | Class and Description |
---|---|
static class |
ZipArchiveEntry.CommentSource
Indicates how the comment of this entry has been determined.
|
static class |
ZipArchiveEntry.NameSource
Indicates how the name of this entry has been determined.
|
Modifier and Type | Field and Description |
---|---|
private int |
alignment |
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 |
private ZipArchiveEntry.CommentSource |
commentSource |
static int |
CRC_UNKNOWN |
private long |
dataOffset |
private static byte[] |
EMPTY |
static int |
ENDCOM |
static int |
ENDHDR |
static int |
ENDOFF |
static long |
ENDSIG |
static int |
ENDSIZ |
static int |
ENDSUB |
static int |
ENDTOT |
static int |
EXTCRC |
private long |
externalAttributes |
static int |
EXTHDR |
static int |
EXTLEN |
private ZipExtraField[] |
extraFields |
static long |
EXTSIG |
static int |
EXTSIZ |
private GeneralPurposeBit |
gpb |
private int |
internalAttributes |
private boolean |
isStreamContiguous |
private long |
localHeaderOffset |
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 |
private int |
method
The
ZipEntry base class only supports
the compression methods STORED and DEFLATED. |
private java.lang.String |
name |
private ZipArchiveEntry.NameSource |
nameSource |
private static ZipExtraField[] |
noExtraFields |
private int |
platform |
static int |
PLATFORM_FAT |
static int |
PLATFORM_UNIX |
private int |
rawFlag |
private byte[] |
rawName |
private static int |
SHORT_MASK |
private static int |
SHORT_SHIFT |
private long |
size
The
ZipEntry.setSize(long) method in the base
class throws an IllegalArgumentException if the size is bigger
than 2GB for Java versions < 7 and even in Java 7+ if the
implementation in java.util.zip doesn't support Zip64 itself
(it is an optional feature). |
private UnparseableExtraFieldData |
unparseableExtra |
private int |
versionMadeBy |
private int |
versionRequired |
SIZE_UNKNOWN
OFFSET_UNKNOWN
Modifier | Constructor and Description |
---|---|
protected |
ZipArchiveEntry() |
|
ZipArchiveEntry(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.
|
|
ZipArchiveEntry(java.lang.String name)
Creates a new zip entry with the specified name.
|
|
ZipArchiveEntry(ZipArchiveEntry entry)
Creates a new zip entry with fields taken from the specified zip entry.
|
|
ZipArchiveEntry(java.util.zip.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.
|
java.lang.Object |
clone()
Overwrite clone.
|
private ZipExtraField[] |
copyOf(ZipExtraField[] src) |
private ZipExtraField[] |
copyOf(ZipExtraField[] src,
int length) |
boolean |
equals(java.lang.Object obj) |
protected int |
getAlignment()
Gets currently configured alignment.
|
private ZipExtraField[] |
getAllExtraFields() |
private ZipExtraField[] |
getAllExtraFieldsNoCopy()
Get all extra fields, including unparseable ones.
|
byte[] |
getCentralDirectoryExtra()
Retrieves the extra data for the central directory.
|
ZipArchiveEntry.CommentSource |
getCommentSource()
The source of the comment field value.
|
long |
getDataOffset()
Gets the offset of data stream within the archive file,
|
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.
|
java.util.Date |
getLastModifiedDate()
Wraps
ZipEntry.getTime() with a Date as the
entry's last modified date. |
byte[] |
getLocalFileDataExtra()
Retrieves the extra data for the local file data.
|
protected long |
getLocalHeaderOffset() |
private ZipExtraField[] |
getMergedFields() |
int |
getMethod()
Returns the compression method of this entry, or -1 if the
compression method has not been specified.
|
java.lang.String |
getName()
Get the name of the entry.
|
ZipArchiveEntry.NameSource |
getNameSource()
The source of the name field value.
|
private ZipExtraField[] |
getParseableExtraFields() |
private ZipExtraField[] |
getParseableExtraFieldsNoCopy() |
int |
getPlatform()
Platform specification to put into the "version made
by" part of the central file header.
|
int |
getRawFlag()
The content of the flags field.
|
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.
|
private ZipExtraField[] |
getUnparseableOnly() |
int |
getVersionMadeBy()
The "version made by" field.
|
int |
getVersionRequired()
The "version required to expand" field.
|
int |
hashCode()
Get the hashCode of the entry.
|
boolean |
isDirectory()
Is this entry a directory?
|
boolean |
isStreamContiguous()
Indicates whether the stream is contiguous, i.e.
|
boolean |
isUnixSymlink()
Returns true if this entry represents a unix symlink,
in which case the entry's content contains the target path
for the symlink.
|
private void |
mergeExtraFields(ZipExtraField[] f,
boolean local)
If there are no extra fields, use the given fields as new extra
data - otherwise merge the fields assuming the existing fields
and the new fields stem from different locations inside the
archive.
|
void |
removeExtraField(ZipShort type)
Remove an extra field.
|
void |
removeUnparseableExtraFieldData()
Removes unparseable extra field data.
|
void |
setAlignment(int alignment)
Sets alignment for this entry.
|
void |
setCentralDirectoryExtra(byte[] b)
Sets the central directory part of extra fields.
|
void |
setCommentSource(ZipArchiveEntry.CommentSource commentSource)
Sets the source of the comment field value.
|
protected void |
setDataOffset(long dataOffset)
Sets the data offset.
|
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.
|
protected void |
setLocalHeaderOffset(long localHeaderOffset) |
void |
setMethod(int method)
Sets the compression method of this entry.
|
protected void |
setName(java.lang.String name)
Set the name of the entry.
|
protected 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.
|
void |
setNameSource(ZipArchiveEntry.NameSource nameSource)
Sets the source of the name field value.
|
protected void |
setPlatform(int platform)
Set the platform (UNIX or FAT).
|
void |
setRawFlag(int rawFlag)
Sets the content of the flags field.
|
void |
setSize(long size)
Sets the uncompressed size of the entry data.
|
protected void |
setStreamContiguous(boolean isStreamContiguous) |
void |
setUnixMode(int mode)
Sets Unix permissions in a way that is understood by Info-Zip's
unzip command.
|
void |
setVersionMadeBy(int versionMadeBy)
Sets the "version made by" field.
|
void |
setVersionRequired(int versionRequired)
Sets the "version required to expand" field.
|
public static final int PLATFORM_UNIX
public static final int PLATFORM_FAT
public static final int CRC_UNKNOWN
private static final int SHORT_MASK
private static final int SHORT_SHIFT
private static final byte[] EMPTY
private int method
ZipEntry
base class only supports
the compression methods STORED and DEFLATED. We override the
field so that any compression methods can be used.
The default value -1 means that the method has not been specified.
private long size
ZipEntry.setSize(long)
method in the base
class throws an IllegalArgumentException if the size is bigger
than 2GB for Java versions < 7 and even in Java 7+ if the
implementation in java.util.zip doesn't support Zip64 itself
(it is an optional feature).
We need to keep our own size information for Zip64 support.
private int internalAttributes
private int versionRequired
private int versionMadeBy
private int platform
private int rawFlag
private long externalAttributes
private int alignment
private ZipExtraField[] extraFields
private UnparseableExtraFieldData unparseableExtra
private java.lang.String name
private byte[] rawName
private GeneralPurposeBit gpb
private static final ZipExtraField[] noExtraFields
private long localHeaderOffset
private long dataOffset
private boolean isStreamContiguous
private ZipArchiveEntry.NameSource nameSource
private ZipArchiveEntry.CommentSource commentSource
public static final long LOCSIG
public static final long EXTSIG
public static final long CENSIG
public static final long ENDSIG
public static final int LOCHDR
public static final int EXTHDR
public static final int CENHDR
public static final int ENDHDR
public static final int LOCVER
public static final int LOCFLG
public static final int LOCHOW
public static final int LOCTIM
public static final int LOCCRC
public static final int LOCSIZ
public static final int LOCLEN
public static final int LOCNAM
public static final int LOCEXT
public static final int EXTCRC
public static final int EXTSIZ
public static final int EXTLEN
public static final int CENVEM
public static final int CENVER
public static final int CENFLG
public static final int CENHOW
public static final int CENTIM
public static final int CENCRC
public static final int CENSIZ
public static final int CENLEN
public static final int CENNAM
public static final int CENEXT
public static final int CENCOM
public static final int CENDSK
public static final int CENATT
public static final int CENATX
public static final int CENOFF
public static final int ENDSUB
public static final int ENDTOT
public static final int ENDSIZ
public static final int ENDOFF
public static final int ENDCOM
public ZipArchiveEntry(java.lang.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 ZipArchiveEntry(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 ZipArchiveEntry(ZipArchiveEntry 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 errorprotected ZipArchiveEntry()
public ZipArchiveEntry(java.io.File inputFile, java.lang.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.
inputFile
- file to create the entry fromentryName
- name of the entrypublic java.lang.Object clone()
clone
in class java.util.zip.ZipEntry
public int getMethod()
getMethod
in class java.util.zip.ZipEntry
public void setMethod(int method)
setMethod
in class java.util.zip.ZipEntry
method
- compression methodpublic int getInternalAttributes()
Note: ZipArchiveInputStream
is unable to fill
this field, you must use ZipFile
if you want to read
entries using this attribute.
public void setInternalAttributes(int value)
value
- an int
valuepublic long getExternalAttributes()
Note: ZipArchiveInputStream
is unable to fill
this field, you must use ZipFile
if you want to read
entries using this attribute.
public void setExternalAttributes(long value)
value
- an long
valuepublic void setUnixMode(int mode)
mode
- an int
valuepublic int getUnixMode()
public boolean isUnixSymlink()
public int getPlatform()
setUnixMode
has been called, in which case PLATFORM_UNIX will be returned.protected void setPlatform(int platform)
platform
- an int
value - 0 is FAT, 3 is UNIXprotected int getAlignment()
public void setAlignment(int alignment)
alignment
- requested alignment, 0 for default.public void setExtraFields(ZipExtraField[] fields)
fields
- an array of extra fieldspublic ZipExtraField[] getExtraFields()
Note: The set of extra fields may be incomplete when
ZipArchiveInputStream
has been used as some extra
fields use the central directory to store additional
information.
public ZipExtraField[] getExtraFields(boolean includeUnparseable)
includeUnparseable
- whether to also return unparseable
extra fields as UnparseableExtraFieldData
if such data
exists.private ZipExtraField[] getParseableExtraFieldsNoCopy()
private ZipExtraField[] getParseableExtraFields()
private ZipExtraField[] getAllExtraFieldsNoCopy()
private ZipExtraField[] copyOf(ZipExtraField[] src)
private ZipExtraField[] copyOf(ZipExtraField[] src, int length)
private ZipExtraField[] getMergedFields()
private ZipExtraField[] getUnparseableOnly()
private ZipExtraField[] getAllExtraFields()
public 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 void addAsFirstExtraField(ZipExtraField ze)
The new extra field will be the first one.
ze
- an extra fieldpublic void removeExtraField(ZipShort type)
type
- the type of extra field to removepublic void removeUnparseableExtraFieldData()
public ZipExtraField getExtraField(ZipShort type)
type
- the header idpublic UnparseableExtraFieldData getUnparseableExtraFieldData()
public void setExtra(byte[] extra) throws java.lang.RuntimeException
UnparseableExtraFieldData
instance.setExtra
in class java.util.zip.ZipEntry
extra
- an array of bytes to be parsed into extra fieldsjava.lang.RuntimeException
- if the bytes cannot be parsedjava.lang.RuntimeException
- on errorprotected 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 setCentralDirectoryExtra(byte[] b)
b
- an array of bytes to be parsed into extra fieldspublic byte[] getLocalFileDataExtra()
public byte[] getCentralDirectoryExtra()
public java.lang.String getName()
This method returns the raw name as it is stored inside of the archive.
getName
in interface ArchiveEntry
getName
in class java.util.zip.ZipEntry
public boolean isDirectory()
isDirectory
in interface ArchiveEntry
isDirectory
in class java.util.zip.ZipEntry
protected void setName(java.lang.String name)
name
- the name to usepublic long getSize()
Note: ZipArchiveInputStream
may create
entries that return SIZE_UNKNOWN
as long
as the entry hasn't been read completely.
getSize
in interface ArchiveEntry
getSize
in class java.util.zip.ZipEntry
public void setSize(long size)
setSize
in class java.util.zip.ZipEntry
size
- the uncompressed size in bytesjava.lang.IllegalArgumentException
- if the specified size is less
than 0protected void setName(java.lang.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
archivepublic byte[] getRawName()
This method will return null if this instance has not been read from an archive.
protected long getLocalHeaderOffset()
protected void setLocalHeaderOffset(long localHeaderOffset)
public long getDataOffset()
EntryStreamOffsets
getDataOffset
in interface EntryStreamOffsets
OFFSET_UNKNOWN
if not known.protected void setDataOffset(long dataOffset)
dataOffset
- new value of data offset.public boolean isStreamContiguous()
EntryStreamOffsets
isStreamContiguous
in interface EntryStreamOffsets
protected void setStreamContiguous(boolean isStreamContiguous)
public int hashCode()
hashCode
in class java.util.zip.ZipEntry
public GeneralPurposeBit getGeneralPurposeBit()
public void setGeneralPurposeBit(GeneralPurposeBit b)
b
- the general purpose bitprivate void mergeExtraFields(ZipExtraField[] f, boolean local) throws java.util.zip.ZipException
f
- the extra fields to mergelocal
- whether the new fields originate from local datajava.util.zip.ZipException
public java.util.Date getLastModifiedDate()
ZipEntry.getTime()
with a Date
as the
entry's last modified date.
Changes to the implementation of ZipEntry.getTime()
leak through and the returned value may depend on your local
time zone as well as your version of Java.
getLastModifiedDate
in interface ArchiveEntry
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public void setVersionMadeBy(int versionMadeBy)
versionMadeBy
- "version made by" fieldpublic void setVersionRequired(int versionRequired)
versionRequired
- "version required to expand" fieldpublic int getVersionRequired()
public int getVersionMadeBy()
public int getRawFlag()
public void setRawFlag(int rawFlag)
rawFlag
- content of the flags fieldpublic ZipArchiveEntry.NameSource getNameSource()
public void setNameSource(ZipArchiveEntry.NameSource nameSource)
nameSource
- source of the name field valuepublic ZipArchiveEntry.CommentSource getCommentSource()
public void setCommentSource(ZipArchiveEntry.CommentSource commentSource)
commentSource
- source of the comment field value