Class ZipArchiveEntry
- java.lang.Object
-
- java.util.zip.ZipEntry
-
- org.apache.commons.compress.archivers.zip.ZipArchiveEntry
-
- All Implemented Interfaces:
java.lang.Cloneable
,ArchiveEntry
,EntryStreamOffsets
- Direct Known Subclasses:
JarArchiveEntry
,ZipFile.Entry
public class ZipArchiveEntry extends java.util.zip.ZipEntry implements ArchiveEntry, EntryStreamOffsets
Extension that adds better handling of extra fields and provides access to the internal and external file attributes.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. 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.
-
Field Summary
Fields Modifier and Type Field 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 long
diskNumberStart
(package private) static ZipArchiveEntry[]
EMPTY_ARRAY
(package private) static java.util.LinkedList<ZipArchiveEntry>
EMPTY_LINKED_LIST
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 boolean
lastModifiedDateSet
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
TheZipEntry
base class only supports the compression methods STORED and DEFLATED.private java.lang.String
name
private ZipArchiveEntry.NameSource
nameSource
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
TheZipEntry.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 long
time
private UnparseableExtraFieldData
unparseableExtra
private int
versionMadeBy
private int
versionRequired
-
Fields inherited from interface org.apache.commons.compress.archivers.ArchiveEntry
SIZE_UNKNOWN
-
Fields inherited from interface org.apache.commons.compress.archivers.EntryStreamOffsets
OFFSET_UNKNOWN
-
-
Constructor Summary
Constructors Modifier Constructor 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(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.util.zip.ZipEntry entry)
Creates a new ZIP entry with fields taken from the specified ZIP entry.ZipArchiveEntry(ZipArchiveEntry entry)
Creates a new ZIP entry with fields taken from the specified ZIP entry.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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.private void
addInfoZipExtendedTimestamp(java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime, java.nio.file.attribute.FileTime creationTime)
private void
addNTFSTimestamp(java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime, java.nio.file.attribute.FileTime creationTime)
private static boolean
canConvertToInfoZipExtendedTimestamp(java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime, java.nio.file.attribute.FileTime creationTime)
java.lang.Object
clone()
Overwrite clone.private ZipExtraField[]
copyOf(ZipExtraField[] src, int length)
boolean
equals(java.lang.Object obj)
private ZipExtraField
findMatching(ZipShort headerId, java.util.List<ZipExtraField> fs)
private ZipExtraField
findUnparseable(java.util.List<ZipExtraField> fs)
protected int
getAlignment()
Gets currently configured alignment.private ZipExtraField[]
getAllExtraFields()
private ZipExtraField[]
getAllExtraFieldsNoCopy()
Gets 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
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()
WrapsZipEntry.getTime()
with aDate
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.private ZipExtraField[]
getMergedFields()
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.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.long
getTime()
int
getUnixMode()
Gets the Unix permission.UnparseableExtraFieldData
getUnparseableExtraFieldData()
Gets up extra field data that couldn't be parsed correctly.private ZipExtraField[]
getUnparseableOnly()
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.private void
internalAddExtraField(ZipExtraField ze)
private void
internalRemoveExtraField(ZipShort type)
private void
internalSetLastModifiedTime(java.nio.file.attribute.FileTime time)
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.private boolean
requiresExtraTimeFields()
void
setAlignment(int alignment)
Sets alignment for this entry.private void
setAttributes(java.nio.file.Path inputPath, java.nio.file.LinkOption... options)
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)
protected void
setDataOffset(long dataOffset)
Sets the data offset.void
setDiskNumberStart(long diskNumberStart)
The number of the split segment this entry starts at.void
setExternalAttributes(long value)
Sets the external file attributes.protected void
setExtra()
UnfortunatelyZipOutputStream
seems to access the extra data directly, so overriding getExtra doesn't help - we need to modify super's data directly and on every update.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.private void
setExtraTimeFields()
void
setGeneralPurposeBit(GeneralPurposeBit b)
The "general purpose bit" field.void
setInternalAttributes(int value)
Sets the internal file attributes.java.util.zip.ZipEntry
setLastAccessTime(java.nio.file.attribute.FileTime time)
java.util.zip.ZipEntry
setLastModifiedTime(java.nio.file.attribute.FileTime time)
protected void
setLocalHeaderOffset(long localHeaderOffset)
void
setMethod(int method)
Sets the compression method of this entry.protected void
setName(java.lang.String name)
Sets 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)
Sets 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
setTime(long time)
void
setTime(java.nio.file.attribute.FileTime fileTime)
Sets the modification time of the entry.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.private void
updateTimeFieldsFromExtraFields()
private void
updateTimeFromExtendedTimestampField()
Workaround for the fact that, as of Java 17,ZipEntry
does not properly modify the entry'sxdostime
field, only settingmtime
.private void
updateTimeFromNtfsField()
Workaround for the fact that, as of Java 17,ZipEntry
parses NTFS timestamps with a maximum precision of microseconds, which is lower than the 100ns precision provided by this extra field.
-
-
-
Field Detail
-
EMPTY_ARRAY
static final ZipArchiveEntry[] EMPTY_ARRAY
-
EMPTY_LINKED_LIST
static java.util.LinkedList<ZipArchiveEntry> EMPTY_LINKED_LIST
-
PLATFORM_UNIX
public static final int PLATFORM_UNIX
- See Also:
- Constant Field Values
-
PLATFORM_FAT
public static final int PLATFORM_FAT
- See Also:
- Constant Field Values
-
CRC_UNKNOWN
public static final int CRC_UNKNOWN
- See Also:
- Constant Field Values
-
SHORT_MASK
private static final int SHORT_MASK
- See Also:
- Constant Field Values
-
SHORT_SHIFT
private static final int SHORT_SHIFT
- See Also:
- Constant Field Values
-
method
private int method
TheZipEntry
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.
- See Also:
- COMPRESS-93
-
size
private long size
TheZipEntry.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.
-
internalAttributes
private int internalAttributes
-
versionRequired
private int versionRequired
-
versionMadeBy
private int versionMadeBy
-
platform
private int platform
-
rawFlag
private int rawFlag
-
externalAttributes
private long externalAttributes
-
alignment
private int alignment
-
extraFields
private ZipExtraField[] extraFields
-
unparseableExtra
private UnparseableExtraFieldData unparseableExtra
-
name
private java.lang.String name
-
rawName
private byte[] rawName
-
gpb
private GeneralPurposeBit gpb
-
localHeaderOffset
private long localHeaderOffset
-
dataOffset
private long dataOffset
-
isStreamContiguous
private boolean isStreamContiguous
-
nameSource
private ZipArchiveEntry.NameSource nameSource
-
commentSource
private ZipArchiveEntry.CommentSource commentSource
-
diskNumberStart
private long diskNumberStart
-
lastModifiedDateSet
private boolean lastModifiedDateSet
-
time
private long time
-
LOCSIG
public static final long LOCSIG
- See Also:
- Constant Field Values
-
EXTSIG
public static final long EXTSIG
- See Also:
- Constant Field Values
-
CENSIG
public static final long CENSIG
- See Also:
- Constant Field Values
-
ENDSIG
public static final long ENDSIG
- See Also:
- Constant Field Values
-
LOCHDR
public static final int LOCHDR
- See Also:
- Constant Field Values
-
EXTHDR
public static final int EXTHDR
- See Also:
- Constant Field Values
-
CENHDR
public static final int CENHDR
- See Also:
- Constant Field Values
-
ENDHDR
public static final int ENDHDR
- See Also:
- Constant Field Values
-
LOCVER
public static final int LOCVER
- See Also:
- Constant Field Values
-
LOCFLG
public static final int LOCFLG
- See Also:
- Constant Field Values
-
LOCHOW
public static final int LOCHOW
- See Also:
- Constant Field Values
-
LOCTIM
public static final int LOCTIM
- See Also:
- Constant Field Values
-
LOCCRC
public static final int LOCCRC
- See Also:
- Constant Field Values
-
LOCSIZ
public static final int LOCSIZ
- See Also:
- Constant Field Values
-
LOCLEN
public static final int LOCLEN
- See Also:
- Constant Field Values
-
LOCNAM
public static final int LOCNAM
- See Also:
- Constant Field Values
-
LOCEXT
public static final int LOCEXT
- See Also:
- Constant Field Values
-
EXTCRC
public static final int EXTCRC
- See Also:
- Constant Field Values
-
EXTSIZ
public static final int EXTSIZ
- See Also:
- Constant Field Values
-
EXTLEN
public static final int EXTLEN
- See Also:
- Constant Field Values
-
CENVEM
public static final int CENVEM
- See Also:
- Constant Field Values
-
CENVER
public static final int CENVER
- See Also:
- Constant Field Values
-
CENFLG
public static final int CENFLG
- See Also:
- Constant Field Values
-
CENHOW
public static final int CENHOW
- See Also:
- Constant Field Values
-
CENTIM
public static final int CENTIM
- See Also:
- Constant Field Values
-
CENCRC
public static final int CENCRC
- See Also:
- Constant Field Values
-
CENSIZ
public static final int CENSIZ
- See Also:
- Constant Field Values
-
CENLEN
public static final int CENLEN
- See Also:
- Constant Field Values
-
CENNAM
public static final int CENNAM
- See Also:
- Constant Field Values
-
CENEXT
public static final int CENEXT
- See Also:
- Constant Field Values
-
CENCOM
public static final int CENCOM
- See Also:
- Constant Field Values
-
CENDSK
public static final int CENDSK
- See Also:
- Constant Field Values
-
CENATT
public static final int CENATT
- See Also:
- Constant Field Values
-
CENATX
public static final int CENATX
- See Also:
- Constant Field Values
-
CENOFF
public static final int CENOFF
- See Also:
- Constant Field Values
-
ENDSUB
public static final int ENDSUB
- See Also:
- Constant Field Values
-
ENDTOT
public static final int ENDTOT
- See Also:
- Constant Field Values
-
ENDSIZ
public static final int ENDSIZ
- See Also:
- Constant Field Values
-
ENDOFF
public static final int ENDOFF
- See Also:
- Constant Field Values
-
ENDCOM
public static final int ENDCOM
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ZipArchiveEntry
protected ZipArchiveEntry()
-
ZipArchiveEntry
public 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.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 to create the entry fromentryName
- name of the entry
-
ZipArchiveEntry
public ZipArchiveEntry(java.util.zip.ZipEntry entry) throws java.util.zip.ZipException
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:
java.util.zip.ZipException
- on error
-
ZipArchiveEntry
public ZipArchiveEntry(java.nio.file.Path inputPath, java.lang.String entryName, java.nio.file.LinkOption... options) throws java.io.IOException
Creates a new ZIP entry taking some information from the given path 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:
inputPath
- path to create the entry from.entryName
- name of the entry.options
- options indicating how symbolic links are handled.- Throws:
java.io.IOException
- if an I/O error occurs.- Since:
- 1.21
-
ZipArchiveEntry
public ZipArchiveEntry(java.lang.String name)
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
-
ZipArchiveEntry
public ZipArchiveEntry(ZipArchiveEntry entry) throws java.util.zip.ZipException
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:
java.util.zip.ZipException
- on error
-
-
Method Detail
-
canConvertToInfoZipExtendedTimestamp
private static boolean canConvertToInfoZipExtendedTimestamp(java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime, java.nio.file.attribute.FileTime creationTime)
-
addAsFirstExtraField
public void addAsFirstExtraField(ZipExtraField ze)
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
-
addExtraField
public void addExtraField(ZipExtraField ze)
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
-
addInfoZipExtendedTimestamp
private void addInfoZipExtendedTimestamp(java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime, java.nio.file.attribute.FileTime creationTime)
-
addNTFSTimestamp
private void addNTFSTimestamp(java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime, java.nio.file.attribute.FileTime creationTime)
-
clone
public java.lang.Object clone()
Overwrite clone.- Overrides:
clone
in classjava.util.zip.ZipEntry
- Returns:
- a cloned copy of this ZipArchiveEntry
-
copyOf
private ZipExtraField[] copyOf(ZipExtraField[] src, int length)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
findMatching
private ZipExtraField findMatching(ZipShort headerId, java.util.List<ZipExtraField> fs)
-
findUnparseable
private ZipExtraField findUnparseable(java.util.List<ZipExtraField> fs)
-
getAlignment
protected int getAlignment()
Gets currently configured alignment.- Returns:
- alignment for this entry.
- Since:
- 1.14
-
getAllExtraFields
private ZipExtraField[] getAllExtraFields()
-
getAllExtraFieldsNoCopy
private ZipExtraField[] getAllExtraFieldsNoCopy()
Gets all extra fields, including unparseable ones.- Returns:
- An array of all extra fields. Not necessarily a copy of internal data structures, hence private method
-
getCentralDirectoryExtra
public byte[] getCentralDirectoryExtra()
Retrieves the extra data for the central directory.- Returns:
- the central directory extra data
-
getCommentSource
public ZipArchiveEntry.CommentSource getCommentSource()
The source of the comment field value.- Returns:
- source of the comment field value
- Since:
- 1.16
-
getDataOffset
public long getDataOffset()
Description copied from interface:EntryStreamOffsets
Gets the offset of data stream within the archive file,- Specified by:
getDataOffset
in interfaceEntryStreamOffsets
- Returns:
- the offset of entry data stream,
OFFSET_UNKNOWN
if not known.
-
getDiskNumberStart
public long getDiskNumberStart()
The number of the split segment this entry starts at.- Returns:
- the number of the split segment this entry starts at.
- Since:
- 1.20
-
getExternalAttributes
public long getExternalAttributes()
Retrieves the external file attributes.Note:
ZipArchiveInputStream
is unable to fill this field, you must useZipFile
if you want to read entries using this attribute.- Returns:
- the external file attributes
-
getExtraField
public ZipExtraField getExtraField(ZipShort type)
Gets an extra field by its header id.- Parameters:
type
- the header id- Returns:
- null if no such field exists.
-
getExtraFields
public ZipExtraField[] getExtraFields()
Gets all extra fields that have been parsed successfully.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.- Returns:
- an array of the extra fields
-
getExtraFields
public ZipExtraField[] getExtraFields(boolean includeUnparseable)
Gets 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
-
getExtraFields
public ZipExtraField[] getExtraFields(ExtraFieldParsingBehavior parsingBehavior) throws java.util.zip.ZipException
Gets extra fields.- Parameters:
parsingBehavior
- controls parsing of extra fields.- Returns:
- an array of the extra fields
- Throws:
java.util.zip.ZipException
- if parsing fails, can not happen ifparsingBehavior
isZipArchiveEntry.ExtraFieldParsingMode.BEST_EFFORT
.- Since:
- 1.19
-
getGeneralPurposeBit
public GeneralPurposeBit getGeneralPurposeBit()
The "general purpose bit" field.- Returns:
- the general purpose bit
- Since:
- 1.1
-
getInternalAttributes
public int getInternalAttributes()
Gets the internal file attributes.Note:
ZipArchiveInputStream
is unable to fill this field, you must useZipFile
if you want to read entries using this attribute.- Returns:
- the internal file attributes
-
getLastModifiedDate
public java.util.Date getLastModifiedDate()
WrapsZipEntry.getTime()
with aDate
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.- Specified by:
getLastModifiedDate
in interfaceArchiveEntry
- Returns:
- the last modified date of this entry.
-
getLocalFileDataExtra
public byte[] getLocalFileDataExtra()
Gets the extra data for the local file data.- Returns:
- the extra data for local file
-
getLocalHeaderOffset
public long getLocalHeaderOffset()
Gets the local header offset.- Returns:
- the local header offset.
- Since:
- 1.24.0
-
getMergedFields
private ZipExtraField[] getMergedFields()
-
getMethod
public int getMethod()
Gets the compression method of this entry, or -1 if the compression method has not been specified.- Overrides:
getMethod
in classjava.util.zip.ZipEntry
- Returns:
- compression method
- Since:
- 1.1
-
getName
public java.lang.String getName()
Gets the name of the entry.This method returns the raw name as it is stored inside of the archive.
- Specified by:
getName
in interfaceArchiveEntry
- Overrides:
getName
in classjava.util.zip.ZipEntry
- Returns:
- the entry name
-
getNameSource
public ZipArchiveEntry.NameSource getNameSource()
The source of the name field value.- Returns:
- source of the name field value
- Since:
- 1.16
-
getParseableExtraFields
private ZipExtraField[] getParseableExtraFields()
-
getParseableExtraFieldsNoCopy
private ZipExtraField[] getParseableExtraFieldsNoCopy()
-
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.
-
getRawFlag
public int getRawFlag()
The content of the flags field.- Returns:
- content of the flags field
- Since:
- 1.11
-
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:
- the raw name bytes
- Since:
- 1.2
-
getSize
public long getSize()
Gets the uncompressed size of the entry data.Note:
ZipArchiveInputStream
may create entries that returnSIZE_UNKNOWN
as long as the entry hasn't been read completely.- Specified by:
getSize
in interfaceArchiveEntry
- Overrides:
getSize
in classjava.util.zip.ZipEntry
- Returns:
- the entry size
-
getTime
public long getTime()
Override to work around bug JDK-8130914
- Overrides:
getTime
in classjava.util.zip.ZipEntry
- Returns:
- The last modification time of the entry in milliseconds since the epoch, or -1 if not specified
- See Also:
setTime(long)
,setLastModifiedTime(FileTime)
-
getUnixMode
public int getUnixMode()
Gets the Unix permission.- Returns:
- the unix permissions
-
getUnparseableExtraFieldData
public UnparseableExtraFieldData getUnparseableExtraFieldData()
Gets up extra field data that couldn't be parsed correctly.- Returns:
- null if no such field exists.
- Since:
- 1.1
-
getUnparseableOnly
private ZipExtraField[] getUnparseableOnly()
-
getVersionMadeBy
public int getVersionMadeBy()
Gets the "version made by" field.- Returns:
- "version made by" field
- Since:
- 1.11
-
getVersionRequired
public int getVersionRequired()
Gets the "version required to expand" field.- Returns:
- "version required to expand" field
- Since:
- 1.11
-
hashCode
public int hashCode()
Gets the hash code of the entry. This uses the name as the hash code.- Overrides:
hashCode
in classjava.util.zip.ZipEntry
- Returns:
- a hash code.
-
internalAddExtraField
private void internalAddExtraField(ZipExtraField ze)
-
internalRemoveExtraField
private void internalRemoveExtraField(ZipShort type)
-
internalSetLastModifiedTime
private void internalSetLastModifiedTime(java.nio.file.attribute.FileTime time)
-
isDirectory
public boolean isDirectory()
Is this entry a directory?- Specified by:
isDirectory
in interfaceArchiveEntry
- Overrides:
isDirectory
in classjava.util.zip.ZipEntry
- Returns:
- true if the entry is a directory
-
isStreamContiguous
public boolean isStreamContiguous()
Description copied from interface:EntryStreamOffsets
Indicates whether the stream is contiguous, i.e. not split among several archive parts, interspersed with control blocks, etc.- Specified by:
isStreamContiguous
in interfaceEntryStreamOffsets
- Returns:
- true if stream is contiguous, false otherwise.
-
isUnixSymlink
public 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.- Returns:
- true if the entry represents a unix symlink, false otherwise.
- Since:
- 1.5
-
mergeExtraFields
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.- Parameters:
f
- the extra fields to mergelocal
- whether the new fields originate from local data
-
removeExtraField
public void removeExtraField(ZipShort type)
Remove an extra field.- Parameters:
type
- the type of extra field to remove
-
removeUnparseableExtraFieldData
public void removeUnparseableExtraFieldData()
Removes unparseable extra field data.- Since:
- 1.1
-
requiresExtraTimeFields
private boolean requiresExtraTimeFields()
-
setAlignment
public void setAlignment(int alignment)
Sets alignment for this entry.- Parameters:
alignment
- requested alignment, 0 for default.- Since:
- 1.14
-
setAttributes
private void setAttributes(java.nio.file.Path inputPath, java.nio.file.LinkOption... options) throws java.io.IOException
- Throws:
java.io.IOException
-
setCentralDirectoryExtra
public void setCentralDirectoryExtra(byte[] b)
Sets the central directory part of extra fields.- Parameters:
b
- an array of bytes to be parsed into extra fields
-
setCommentSource
public void setCommentSource(ZipArchiveEntry.CommentSource commentSource)
Sets the source of the comment field value.- Parameters:
commentSource
- source of the comment field value- Since:
- 1.16
-
setCreationTime
public java.util.zip.ZipEntry setCreationTime(java.nio.file.attribute.FileTime time)
- Overrides:
setCreationTime
in classjava.util.zip.ZipEntry
-
setDataOffset
protected void setDataOffset(long dataOffset)
Sets the data offset.- Parameters:
dataOffset
- new value of data offset.
-
setDiskNumberStart
public void setDiskNumberStart(long diskNumberStart)
The number of the split segment this entry starts at.- Parameters:
diskNumberStart
- the number of the split segment this entry starts at.- Since:
- 1.20
-
setExternalAttributes
public void setExternalAttributes(long value)
Sets the external file attributes.- Parameters:
value
- anlong
value
-
setExtra
protected void setExtra()
UnfortunatelyZipOutputStream
seems to access the extra data directly, so overriding getExtra doesn't help - we need to modify super's data directly and on every update.
-
setExtra
public void setExtra(byte[] extra) throws java.lang.RuntimeException
Parses the given bytes as extra field data and consumes any unparseable data as anUnparseableExtraFieldData
instance.- Overrides:
setExtra
in classjava.util.zip.ZipEntry
- Parameters:
extra
- an array of bytes to be parsed into extra fields- Throws:
java.lang.RuntimeException
- if the bytes cannot be parsedjava.lang.RuntimeException
- on error
-
setExtraFields
public void setExtraFields(ZipExtraField[] fields)
Replaces all currently attached extra fields with the new array.- Parameters:
fields
- an array of extra fields
-
setExtraTimeFields
private void setExtraTimeFields()
-
setGeneralPurposeBit
public void setGeneralPurposeBit(GeneralPurposeBit b)
The "general purpose bit" field.- Parameters:
b
- the general purpose bit- Since:
- 1.1
-
setInternalAttributes
public void setInternalAttributes(int value)
Sets the internal file attributes.- Parameters:
value
- anint
value
-
setLastAccessTime
public java.util.zip.ZipEntry setLastAccessTime(java.nio.file.attribute.FileTime time)
- Overrides:
setLastAccessTime
in classjava.util.zip.ZipEntry
-
setLastModifiedTime
public java.util.zip.ZipEntry setLastModifiedTime(java.nio.file.attribute.FileTime time)
- Overrides:
setLastModifiedTime
in classjava.util.zip.ZipEntry
-
setLocalHeaderOffset
protected void setLocalHeaderOffset(long localHeaderOffset)
-
setMethod
public void setMethod(int method)
Sets the compression method of this entry.- Overrides:
setMethod
in classjava.util.zip.ZipEntry
- Parameters:
method
- compression method- Since:
- 1.1
-
setName
protected void setName(java.lang.String name)
Sets the name of the entry.- Parameters:
name
- the name to use
-
setName
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.- 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- Since:
- 1.2
-
setNameSource
public void setNameSource(ZipArchiveEntry.NameSource nameSource)
Sets the source of the name field value.- Parameters:
nameSource
- source of the name field value- Since:
- 1.16
-
setPlatform
protected void setPlatform(int platform)
Sets the platform (UNIX or FAT).- Parameters:
platform
- anint
value - 0 is FAT, 3 is UNIX
-
setRawFlag
public void setRawFlag(int rawFlag)
Sets the content of the flags field.- Parameters:
rawFlag
- content of the flags field- Since:
- 1.11
-
setSize
public void setSize(long size)
Sets the uncompressed size of the entry data.- Overrides:
setSize
in classjava.util.zip.ZipEntry
- Parameters:
size
- the uncompressed size in bytes- Throws:
java.lang.IllegalArgumentException
- if the specified size is less than 0
-
setStreamContiguous
protected void setStreamContiguous(boolean isStreamContiguous)
-
setTime
public void setTime(java.nio.file.attribute.FileTime fileTime)
Sets the modification time of the entry.- Parameters:
fileTime
- the entry modification time.- Since:
- 1.21
-
setTime
public void setTime(long time)
Override to work around bug JDK-8130914
- Overrides:
setTime
in classjava.util.zip.ZipEntry
- Parameters:
time
- The last modification time of the entry in milliseconds since the epoch- See Also:
getTime()
,ZipEntry.getLastModifiedTime()
-
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
-
setVersionMadeBy
public void setVersionMadeBy(int versionMadeBy)
Sets the "version made by" field.- Parameters:
versionMadeBy
- "version made by" field- Since:
- 1.11
-
setVersionRequired
public void setVersionRequired(int versionRequired)
Sets the "version required to expand" field.- Parameters:
versionRequired
- "version required to expand" field- Since:
- 1.11
-
updateTimeFieldsFromExtraFields
private void updateTimeFieldsFromExtraFields()
-
updateTimeFromExtendedTimestampField
private void updateTimeFromExtendedTimestampField()
Workaround for the fact that, as of Java 17,ZipEntry
does not properly modify the entry'sxdostime
field, only settingmtime
. While this is not strictly necessary, it's better to maintain the same behavior between this and the NTFS field.
-
updateTimeFromNtfsField
private void updateTimeFromNtfsField()
Workaround for the fact that, as of Java 17,ZipEntry
parses NTFS timestamps with a maximum precision of microseconds, which is lower than the 100ns precision provided by this extra field.
-
-