Top Description Inners Fields Constructors Methods
org.apache.commons.compress.archivers.zip

public Class ZipArchiveEntry

extends ZipEntry
implements ArchiveEntry, EntryStreamOffsets
Class Inheritance
All Implemented Interfaces
org.apache.commons.compress.archivers.EntryStreamOffsets, org.apache.commons.compress.archivers.ArchiveEntry
Known Direct Subclasses
org.apache.commons.compress.archivers.zip.ZipFile.Entry, org.apache.commons.compress.archivers.jar.JarArchiveEntry
Imports
java.io.File, .IOException, java.nio.file.Files, .LinkOption, .Path, java.nio.file.attribute.BasicFileAttributes, .FileTime, java.util.ArrayList, .Arrays, .Date, .LinkedList, .List, .NoSuchElementException, .Objects, java.util.function.Function, java.util.zip.ZipEntry, .ZipException, org.apache.commons.compress.archivers.ArchiveEntry, .EntryStreamOffsets, org.apache.commons.compress.utils.ByteUtils, .TimeUtils

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:

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 and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ZipArchiveEntry.CommentSource

Indicates how the comment of this entry has been determined.

public static enum
ZipArchiveEntry.ExtraFieldParsingMode

How to try to parse the extra fields.

public static enum
ZipArchiveEntry.NameSource

Indicates how the name of this entry has been determined.

Field Summary

Modifier and TypeField and Description
private int
private ZipArchiveEntry.CommentSource
public static final int
private long
private long
pack-priv static final ZipArchiveEntry[]
pack-priv static LinkedList<ZipArchiveEntry>
private long
private final Function<ZipShort, ZipExtraField>
private ZipExtraField[]
private GeneralPurposeBit
private int
private boolean
private boolean
private long
private int
method

Hides java.util.zip.ZipEntry.method.

The java.util.zip.ZipEntry base class only supports the compression methods STORED and DEFLATED.
private String
private ZipArchiveEntry.NameSource
private int
public static final int
public static final int
private int
private byte[]
private static final int
private static final int
private long
size

Hides java.util.zip.ZipEntry.size.

The java.util.zip.ZipEntry#setSize 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
private UnparseableExtraFieldData
private int
private int
private static final String
Inherited from java.util.zip.ZipEntry:
DEFLATEDSTORED

Constructor Summary

AccessConstructor and Description
protected
public
ZipArchiveEntry(final File
file to create the entry from
inputFile
,
final String
name of the entry
entryName
)

Creates a new ZIP entry taking some information from the given file and using the provided name.

private
ZipArchiveEntry(final Function<ZipShort, ZipExtraField>
custom lookup factory for extra fields or null
extraFieldFactory
,
final File
file to create the entry from
inputFile
,
final String
name of the entry
entryName
)

Creates a new ZIP entry taking some information from the given file and using the provided name.

private
ZipArchiveEntry(final Function<ZipShort, ZipExtraField>
the extra field lookup factory.
extraFieldFactory
,
final ZipEntry
the entry to get fields from
entry
)

Creates a new ZIP entry with fields taken from the specified ZIP entry.

private
ZipArchiveEntry(final Function<ZipShort, ZipExtraField>
custom lookup factory for extra fields or null
extraFieldFactory
,
final Path
path to create the entry from.
inputPath
,
final String
name of the entry.
entryName
,
final LinkOption...
options indicating how symbolic links are handled.
options
)

Creates a new ZIP entry taking some information from the given path and using the provided name.

private
ZipArchiveEntry(final Function<ZipShort, ZipExtraField>
custom lookup factory for extra fields or null
extraFieldFactory
,
final String
the name of the entry
name
)

Creates a new ZIP entry with the specified name.

public
ZipArchiveEntry(final ZipEntry
the entry to get fields from
entry
)

Creates a new ZIP entry with fields taken from the specified ZIP entry.

public
ZipArchiveEntry(final Path
path to create the entry from.
inputPath
,
final String
name of the entry.
entryName
,
final LinkOption...
options indicating how symbolic links are handled.
options
)

Creates a new ZIP entry taking some information from the given path and using the provided name.

public
ZipArchiveEntry(final String
the name of the entry
name
)

Creates a new ZIP entry with the specified name.

public
ZipArchiveEntry(final ZipArchiveEntry
the entry to get fields from
entry
)

Creates a new ZIP entry with fields taken from the specified ZIP entry.

Method Summary

Modifier and TypeMethod and Description
public void
addAsFirstExtraField(final ZipExtraField
an extra field
ze
)

Adds an extra field - replacing an already present extra field of the same type.

public void
addExtraField(final ZipExtraField
an extra field
ze
)

Adds an extra field - replacing an already present extra field of the same type.

private void
addInfoZipExtendedTimestamp(final FileTime lastModifiedTime, final FileTime lastAccessTime, final FileTime creationTime)

private void
addNTFSTimestamp(final FileTime lastModifiedTime, final FileTime lastAccessTime, final FileTime creationTime)

private static boolean
canConvertToInfoZipExtendedTimestamp(final FileTime lastModifiedTime, final FileTime lastAccessTime, final FileTime creationTime)

public Object

Returns:

a cloned copy of this ZipArchiveEntry
clone
()

Overrides java.util.zip.ZipEntry.clone.

Overwrite clone.
private ZipExtraField[]
copyOf(final ZipExtraField[] src, final int length)

public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private ZipExtraField
findMatching(final ZipShort headerId, final List<ZipExtraField> fs)

private ZipExtraField
protected int

Returns:

alignment for this entry.
getAlignment
()

Gets currently configured alignment.

private ZipExtraField[]
private ZipExtraField[]

Returns:

An array of all extra fields. Not necessarily a copy of internal data structures, hence private method
getAllExtraFieldsNoCopy
()

Gets all extra fields, including unparseable ones.

public byte[]

Returns:

the central directory extra data
getCentralDirectoryExtra
()

Retrieves the extra data for the central directory.

public ZipArchiveEntry.CommentSource

Returns:

source of the comment field value
getCommentSource
()

The source of the comment field value.

public long
getDataOffset()

Implements org.apache.commons.compress.archivers.EntryStreamOffsets.getDataOffset.

Gets the offset of data stream within the archive file,
public long

Returns:

the number of the split segment this entry starts at.
getDiskNumberStart
()

The number of the split segment this entry starts at.

public long

Returns:

the external file attributes
getExternalAttributes
()

Retrieves the external file attributes.

public ZipExtraField

Returns:

null if no such field exists.
getExtraField
(final ZipShort
the header id
type
)

Gets an extra field by its header id.

public ZipExtraField[]

Returns:

an array of the extra fields
getExtraFields
()

Gets all extra fields that have been parsed successfully.

public ZipExtraField[]

Returns:

an array of the extra fields
getExtraFields
(final boolean
whether to also return unparseable extra fields as UnparseableExtraFieldData if such data exists.
includeUnparseable
)

Gets extra fields.

public ZipExtraField[]

Returns:

an array of the extra fields
getExtraFields
(final ExtraFieldParsingBehavior
controls parsing of extra fields.
parsingBehavior
)

Gets extra fields.

public GeneralPurposeBit

Returns:

the general purpose bit
getGeneralPurposeBit
()

The "general purpose bit" field.

public int

Returns:

the internal file attributes
getInternalAttributes
()

Gets the internal file attributes.

public Date
public byte[]

Returns:

the extra data for local file
getLocalFileDataExtra
()

Gets the extra data for the local file data.

public long

Returns:

the local header offset.
getLocalHeaderOffset
()

Gets the local header offset.

private ZipExtraField[]
public int

Returns:

compression method
getMethod
()

Overrides java.util.zip.ZipEntry.getMethod.

Gets the compression method of this entry, or -1 if the compression method has not been specified.
public String

Returns:

the entry name
getName
()

Overrides java.util.zip.ZipEntry.getName.

Implements org.apache.commons.compress.archivers.ArchiveEntry.getName.

Gets the name of the entry.
public ZipArchiveEntry.NameSource

Returns:

source of the name field value
getNameSource
()

The source of the name field value.

private ZipExtraField[]
private ZipExtraField[]
public int

Returns:

PLATFORM_FAT unless setUnixMode has been called, in which case PLATFORM_UNIX will be returned.
getPlatform
()

Platform specification to put into the "version made by" part of the central file header.

public int

Returns:

content of the flags field
getRawFlag
()

The content of the flags field.

public byte[]

Returns:

the raw name bytes
getRawName
()

Returns the raw bytes that made up the name before it has been converted using the configured or guessed encoding.

public long

Returns:

the entry size
getSize
()

Overrides java.util.zip.ZipEntry.getSize.

Implements org.apache.commons.compress.archivers.ArchiveEntry.getSize.

Gets the uncompressed size of the entry data.
public long

Returns:

The last modification time of the entry in milliseconds since the epoch, or -1 if not specified
getTime
()

Overrides java.util.zip.ZipEntry.getTime.

Returns the last modification time of the entry.
public int

Returns:

the unix permissions
getUnixMode
()

Gets the Unix permission.

public UnparseableExtraFieldData

Returns:

null if no such field exists.
getUnparseableExtraFieldData
()

Gets up extra field data that couldn't be parsed correctly.

private ZipExtraField[]
public int

Returns:

"version made by" field
getVersionMadeBy
()

Gets the "version made by" field.

public int

Returns:

"version required to expand" field
getVersionRequired
()

Gets the "version required to expand" field.

public int

Returns:

a hash code.
hashCode
()

Overrides java.util.zip.ZipEntry.hashCode.

Gets the hash code of the entry.
private void
private void
private void
public boolean

Returns:

true if the entry is a directory
isDirectory
()

Overrides java.util.zip.ZipEntry.isDirectory.

Implements org.apache.commons.compress.archivers.ArchiveEntry.isDirectory.

Is this entry a directory?
private static boolean
isDirectoryEntryName(final String entryName)

public boolean
isStreamContiguous()

Implements org.apache.commons.compress.archivers.EntryStreamOffsets.isStreamContiguous.

Indicates whether the stream is contiguous, i.e. not split among several archive parts, interspersed with control blocks, etc.
private void
mergeExtraFields(final ZipExtraField[]
the extra fields to merge
f
,
final boolean
whether the new fields originate from local data
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.

private ZipExtraField[]
parseExtraFields(final byte[] data, final boolean local, final ExtraFieldParsingBehavior parsingBehavior)

public void
removeExtraField(final ZipShort
the type of extra field to remove
type
)

Remove an extra field.

public void
removeUnparseableExtraFieldData()

Removes unparseable extra field data.

private boolean
public void
setAlignment(final int
requested alignment, 0 for default.
alignment
)

Sets alignment for this entry.

private void
setAttributes(final Path inputPath, final LinkOption... options)

public void
setCentralDirectoryExtra(final byte[]
an array of bytes to be parsed into extra fields
b
)

Sets the central directory part of extra fields.

public void
setCommentSource(final ZipArchiveEntry.CommentSource
source of the comment field value
commentSource
)

Sets the source of the comment field value.

public ZipEntry
setCreationTime(final FileTime
The creation time of the entry
time
)

Overrides java.util.zip.ZipEntry.setCreationTime.

Sets the creation time of the entry.
protected void
setDataOffset(final long
new value of data offset.
dataOffset
)

Sets the data offset.

public void
setDiskNumberStart(final long
the number of the split segment this entry starts at.
diskNumberStart
)

The number of the split segment this entry starts at.

public void
setExternalAttributes(final long
an long value
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 and on every update.

public void
setExtra(final byte[]
an array of bytes to be parsed into extra fields
extra
)

Overrides java.util.zip.ZipEntry.setExtra.

Parses the given bytes as extra field data and consumes any unparseable data as an UnparseableExtraFieldData instance.
public void
setExtraFields(final ZipExtraField[]
an array of extra fields
fields
)

Replaces all currently attached extra fields with the new array.

private void
public void
setGeneralPurposeBit(final GeneralPurposeBit
the general purpose bit
generalPurposeBit
)

Sets the "general purpose bit" field.

public void
setInternalAttributes(final int
an int value
internalAttributes
)

Sets the internal file attributes.

public ZipEntry
setLastAccessTime(final FileTime
The last access time of the entry
fileTime
)

Overrides java.util.zip.ZipEntry.setLastAccessTime.

Sets the last access time of the entry.
public ZipEntry
setLastModifiedTime(final FileTime
The last modification time of the entry
fileTime
)

Overrides java.util.zip.ZipEntry.setLastModifiedTime.

Sets the last modification time of the entry.
protected void
setLocalHeaderOffset(final long localHeaderOffset)

public void
setMethod(final int
compression method
method
)

Overrides java.util.zip.ZipEntry.setMethod.

Sets the compression method of this entry.
protected void
setName(String
the name to use
name
)

Sets the name of the entry.

protected void
setName(final String
the name to use created from the raw bytes using the guessed or configured encoding
name
,
final byte[]
the bytes originally read as name from the archive
rawName
)

Sets the name using the raw bytes and the string created from it by guessing or using the configured encoding.

public void
setNameSource(final ZipArchiveEntry.NameSource
source of the name field value
nameSource
)

Sets the source of the name field value.

protected void
setPlatform(final int
an int value - 0 is FAT, 3 is UNIX
platform
)

Sets the platform (UNIX or FAT).

public void
setRawFlag(final int
content of the flags field
rawFlag
)

Sets the content of the flags field.

public void
setSize(final long
the uncompressed size in bytes
size
)

Overrides java.util.zip.ZipEntry.setSize.

Sets the uncompressed size of the entry data.
protected void
setStreamContiguous(final boolean isStreamContiguous)

public void
setTime(final FileTime
the entry modification time.
fileTime
)

Sets the modification time of the entry.

public void
setTime(final long
The last modification time of the entry in milliseconds since the epoch.
timeEpochMillis
)

Overrides java.util.zip.ZipEntry.setTime.

Sets the last modification time of the entry.
public void
setUnixMode(final int
an int value
mode
)

Sets Unix permissions in a way that is understood by Info-Zip's unzip command.

public void
setVersionMadeBy(final int
"version made by" field
versionMadeBy
)

Sets the "version made by" field.

public void
setVersionRequired(final int
"version required to expand" field
versionRequired
)

Sets the "version required to expand" field.

private static String
toDirectoryEntryName(final String entryName)

private static String
toEntryName(final File inputFile, final String entryName)

private static String
toEntryName(final Path inputPath, final String entryName, final LinkOption... options)

private void
private void
updateTimeFromExtendedTimestampField()

Workaround for the fact that, as of Java 17, java.util.zip.ZipEntry does not properly modify the entry's xdostime field, only setting mtime.

private void
updateTimeFromNtfsField()

Workaround for the fact that, as of Java 17, java.util.zip.ZipEntry parses NTFS timestamps with a maximum precision of microseconds, which is lower than the 100ns precision provided by this extra field.

Inherited from java.util.zip.ZipEntry:
getCommentgetCompressedSizegetCrcgetCreationTimegetExtragetLastAccessTimegetLastModifiedTimegetTimeLocalsetCommentsetCompressedSizesetCrcsetTimeLocaltoString