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.ExtraFieldParsingMode
How to try to parse the extra fields.
|
static class |
ZipArchiveEntry.NameSource
Indicates how the name of this entry has been determined.
|
| 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 |
SIZE_UNKNOWNOFFSET_UNKNOWN| Constructor and Description |
|---|
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.nio.file.Path inputPath,
java.lang.String entryName,
java.nio.file.LinkOption... options)
Creates a new ZIP entry taking some information from the given path 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.
|
boolean |
equals(java.lang.Object obj) |
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 |
getDiskNumberStart()
The number of the split segment this entry starts at.
|
long |
getExternalAttributes()
Retrieves the external file attributes.
|
ZipExtraField |
getExtraField(ZipShort type)
Gets an extra field by its header id.
|
ZipExtraField[] |
getExtraFields()
Gets all extra fields that have been parsed successfully.
|
ZipExtraField[] |
getExtraFields(boolean includeUnparseable)
Gets extra fields.
|
ZipExtraField[] |
getExtraFields(ExtraFieldParsingBehavior parsingBehavior)
Gets extra fields.
|
GeneralPurposeBit |
getGeneralPurposeBit()
The "general purpose bit" field.
|
int |
getInternalAttributes()
Gets the internal file attributes.
|
java.util.Date |
getLastModifiedDate()
Wraps
ZipEntry.getTime() with a Date as the entry's last modified date. |
byte[] |
getLocalFileDataExtra()
Gets the extra data for the local file data.
|
long |
getLocalHeaderOffset()
Gets the local header offset.
|
int |
getMethod()
Gets the compression method of this entry, or -1 if the compression method has not been specified.
|
java.lang.String |
getName()
Gets the name of the entry.
|
ZipArchiveEntry.NameSource |
getNameSource()
The source of the name field value.
|
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.
|
long |
getTime() |
int |
getUnixMode()
Gets the Unix permission.
|
UnparseableExtraFieldData |
getUnparseableExtraFieldData()
Gets up extra field data that couldn't be parsed correctly.
|
int |
getVersionMadeBy()
Gets the "version made by" field.
|
int |
getVersionRequired()
Gets the "version required to expand" field.
|
int |
hashCode()
Gets the hash code of the entry.
|
boolean |
isDirectory()
Is this entry a directory?
|
boolean |
isStreamContiguous()
Tests whether the stream is contiguous, that is, not split among several archive parts, interspersed with control blocks, and so on.
|
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.
|
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.
|
java.util.zip.ZipEntry |
setCreationTime(java.nio.file.attribute.FileTime time) |
void |
setDiskNumberStart(long diskNumberStart)
The number of the split segment this entry starts at.
|
void |
setExternalAttributes(long value)
Sets the external file attributes.
|
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 generalPurposeBit)
Sets the "general purpose bit" field.
|
void |
setInternalAttributes(int internalAttributes)
Sets the internal file attributes.
|
java.util.zip.ZipEntry |
setLastAccessTime(java.nio.file.attribute.FileTime fileTime) |
java.util.zip.ZipEntry |
setLastModifiedTime(java.nio.file.attribute.FileTime fileTime) |
void |
setMethod(int method)
Sets the compression method of this entry.
|
void |
setNameSource(ZipArchiveEntry.NameSource nameSource)
Sets the source of the name field value.
|
void |
setRawFlag(int rawFlag)
Sets the content of the flags field.
|
void |
setSize(long size)
Sets the uncompressed size of the entry data.
|
void |
setTime(java.nio.file.attribute.FileTime fileTime)
Sets the modification time of the entry.
|
void |
setTime(long timeEpochMillis) |
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.
|
getComment, getCompressedSize, getCrc, getCreationTime, getExtra, getLastAccessTime, getLastModifiedTime, setComment, setCompressedSize, setCrc, toStringresolveInpublic static final int PLATFORM_UNIX
public static final int PLATFORM_FAT
public static final int CRC_UNKNOWN
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.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 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(java.nio.file.Path inputPath,
java.lang.String entryName,
java.nio.file.LinkOption... options)
throws java.io.IOException
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.
inputPath - path to create the entry from.entryName - name of the entry.options - options indicating how symbolic links are handled.java.io.IOException - if an I/O error occurs.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(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 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 java.lang.Object clone()
clone in class java.util.zip.ZipEntrypublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic byte[] getCentralDirectoryExtra()
public ZipArchiveEntry.CommentSource getCommentSource()
public long getDataOffset()
EntryStreamOffsetsgetDataOffset in interface EntryStreamOffsetsOFFSET_UNKNOWN if not known.public long getDiskNumberStart()
public long getExternalAttributes()
Note: ZipArchiveInputStream is unable to fill this field, you must use ZipFile if you want to read entries using this attribute.
public ZipExtraField getExtraField(ZipShort type)
type - the header idpublic 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.public ZipExtraField[] getExtraFields(ExtraFieldParsingBehavior parsingBehavior) throws java.util.zip.ZipException
parsingBehavior - controls parsing of extra fields.java.util.zip.ZipException - if parsing fails, can not happen if parsingBehavior is ZipArchiveEntry.ExtraFieldParsingMode.BEST_EFFORT.public GeneralPurposeBit getGeneralPurposeBit()
public int getInternalAttributes()
Note: ZipArchiveInputStream is unable to fill this field, you must use ZipFile if you want to read entries using this attribute.
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 ArchiveEntrypublic byte[] getLocalFileDataExtra()
public long getLocalHeaderOffset()
public int getMethod()
getMethod in class java.util.zip.ZipEntrypublic java.lang.String getName()
This method returns the raw name as it is stored inside of the archive.
getName in interface ArchiveEntrygetName in class java.util.zip.ZipEntrypublic ZipArchiveEntry.NameSource getNameSource()
public int getPlatform()
setUnixMode has been called, in which case PLATFORM_UNIX will be returned.public int getRawFlag()
public byte[] getRawName()
This method will return null if this instance has not been read from an archive.
public long getSize()
Note: ZipArchiveInputStream may create entries that return SIZE_UNKNOWN as long as the entry hasn't been read
completely.
getSize in interface ArchiveEntrygetSize in class java.util.zip.ZipEntrypublic long getTime()
Override to work around bug JDK-8130914
getTime in class java.util.zip.ZipEntrysetTime(long),
setLastModifiedTime(FileTime)public int getUnixMode()
public UnparseableExtraFieldData getUnparseableExtraFieldData()
public int getVersionMadeBy()
public int getVersionRequired()
public int hashCode()
hashCode in class java.util.zip.ZipEntrypublic boolean isDirectory()
isDirectory in interface ArchiveEntryisDirectory in class java.util.zip.ZipEntrypublic boolean isStreamContiguous()
EntryStreamOffsetsisStreamContiguous in interface EntryStreamOffsetspublic boolean isUnixSymlink()
public void removeExtraField(ZipShort type)
type - the type of extra field to removepublic void removeUnparseableExtraFieldData()
public void setAlignment(int alignment)
alignment - requested alignment, 0 for default.public void setCentralDirectoryExtra(byte[] b)
b - an array of bytes to be parsed into extra fieldspublic void setCommentSource(ZipArchiveEntry.CommentSource commentSource)
commentSource - source of the comment field valuepublic java.util.zip.ZipEntry setCreationTime(java.nio.file.attribute.FileTime time)
setCreationTime in class java.util.zip.ZipEntrypublic void setDiskNumberStart(long diskNumberStart)
diskNumberStart - the number of the split segment this entry starts at.public void setExternalAttributes(long value)
value - an long valuepublic void setExtra(byte[] extra)
throws java.lang.RuntimeException
UnparseableExtraFieldData instance.setExtra in class java.util.zip.ZipEntryextra - an array of bytes to be parsed into extra fieldsjava.lang.RuntimeException - if the bytes cannot be parsedjava.lang.RuntimeException - on errorpublic void setExtraFields(ZipExtraField[] fields)
fields - an array of extra fieldspublic void setGeneralPurposeBit(GeneralPurposeBit generalPurposeBit)
generalPurposeBit - the general purpose bitpublic void setInternalAttributes(int internalAttributes)
internalAttributes - an int valuepublic java.util.zip.ZipEntry setLastAccessTime(java.nio.file.attribute.FileTime fileTime)
setLastAccessTime in class java.util.zip.ZipEntrypublic java.util.zip.ZipEntry setLastModifiedTime(java.nio.file.attribute.FileTime fileTime)
setLastModifiedTime in class java.util.zip.ZipEntrypublic void setMethod(int method)
setMethod in class java.util.zip.ZipEntrymethod - compression methodpublic void setNameSource(ZipArchiveEntry.NameSource nameSource)
nameSource - source of the name field valuepublic void setRawFlag(int rawFlag)
rawFlag - content of the flags fieldpublic void setSize(long size)
setSize in class java.util.zip.ZipEntrysize - the uncompressed size in bytesjava.lang.IllegalArgumentException - if the specified size is less than 0public void setTime(java.nio.file.attribute.FileTime fileTime)
fileTime - the entry modification time.public void setTime(long timeEpochMillis)
Override to work around bug JDK-8130914
setTime in class java.util.zip.ZipEntrytimeEpochMillis - The last modification time of the entry in milliseconds since the epoch.getTime(),
ZipEntry.getLastModifiedTime()public void setUnixMode(int mode)
mode - an int valuepublic void setVersionMadeBy(int versionMadeBy)
versionMadeBy - "version made by" fieldpublic void setVersionRequired(int versionRequired)
versionRequired - "version required to expand" fieldCopyright © 2010 - 2024 Adobe. All Rights Reserved