org.at4j.zip
Class ZipEntry

java.lang.Object
  extended by org.at4j.archive.AbstractArchiveEntry<ZipEntry,ZipDirectoryEntry>
      extended by org.at4j.zip.ZipEntry
All Implemented Interfaces:
ArchiveEntry<ZipEntry,ZipDirectoryEntry>, Lockable, ReadLockable, Named
Direct Known Subclasses:
ZipDirectoryEntry, ZipFileEntry, ZipSymbolicLinkEntry

public abstract class ZipEntry
extends AbstractArchiveEntry<ZipEntry,ZipDirectoryEntry>

This is an abstract base class for Zip entries. It contains the metadata that is present for all Zip entries, regardless of their types.

Zip entries contains the following information:

Property Description
Version used to create The equivalent version of the PK-Zip software that was used to create the entry.
Version needed to extract The equivalent version of the PK-Zip software that is needed to extract the entry.
Last modification time The last modification time for the file system entity (file, directory) that was used to create the Zip entry.
ZipGeneralPurposeBitFlags Various information. Some of it is compression method-specific.
Comment A text comment for the Zip entry.
External file attributes Attributes for the entry. There are several different ways of interpreting these attributes. Some of the ways are included in this package as ZipExternalFileAttributes implementations.
Extra fields Zero or more extra fields (ZipEntryExtraField:s) that contain custom metadata for the entry. An extra field for an entry always has two instances – the local header instance and the central directory instance.

Zip entry objects are always immutable.

Since:
1.0
Author:
Karl Gustafsson

Constructor Summary
protected ZipEntry(ZipEntryCollaborator collaborator, AbsoluteLocation loc)
          Create a new Zip entry.
protected ZipEntry(ZipEntryCollaborator collaborator, ZipEntryCentralFileHeaderData zecd, ZipEntryLocalFileHeaderData zeld)
          Create a new Zip entry.
 
Method Summary
 String getComment()
          Get the Zip entry's comment.
 UnsignedShort getDiskNumberStart()
          Get the number of the disk where this Zip entry begins.
 ZipExternalFileAttributes getExternalFileAttributes()
          Get the external file attributes value.
<T> T
getExtraField(Class<T> type, boolean localHeader)
          Get the first extra field found that matches the description.
 Collection<ZipEntryExtraField> getExtraFields()
          Get a read only collection containing the Zip entry's extra fields.
 ZipGeneralPurposeBitFlags getGeneralPurposeBitFlags()
          Get the Zip entry's general purpose bit flags.
 Date getLastModified()
          Get the instant in time when the file or directory entity that was used to create this Zip entry was last modified.
 UnsignedByte getVersionNeededToExtract()
          Get the earliest PK-Zip version that can extract this Zip entry.
 UnsignedByte getVersionUsedToCreate()
          Get the PK-Zip version (or equivalent) that was used to create this Zip entry.
 boolean isEncrypted()
          Is the Zip entry encrypted?
 boolean isStrongEncryption()
          Is the Zip entry encrypted with strong encryption?
 
Methods inherited from class org.at4j.archive.AbstractArchiveEntry
getCollaborator, getLocation, getName, getParent, getReadLock, isReadLockedByCurrentThread, lockForReading
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZipEntry

protected ZipEntry(ZipEntryCollaborator collaborator,
                   AbsoluteLocation loc)
Create a new Zip entry. This constructor is only used for Zip directory entries that don't have an actual entry in the Zip file, but that has child entries anyway.

The Zip entry is assigned default values for all of its properties:

Property Value
External file attributes MsDosExternalFileAttributes.DEFAULT_DIRECTORY_ATTRIBUTES
Version used to create 10 (meaning 1.0)
Version needed to extract 10 (meaning 1.0)
General purpose bit flags empty
Last modification time The current time
Extra fields none
Comment Empty string

Parameters:
collaborator - The parent Zip archive's entry collaborator.
loc - The location of the entry in the Zip file.

ZipEntry

protected ZipEntry(ZipEntryCollaborator collaborator,
                   ZipEntryCentralFileHeaderData zecd,
                   ZipEntryLocalFileHeaderData zeld)
Create a new Zip entry.

Parameters:
collaborator - The parent Zip archive's entry collaborator.
zecd - Data parsed from the entry's central directory record.
zeld - Data parsed from the entry's local header.
Method Detail

getVersionUsedToCreate

public UnsignedByte getVersionUsedToCreate()
Get the PK-Zip version (or equivalent) that was used to create this Zip entry. The version method is the version * 10, i.e. if this method returns 23, that corresponds to the version 2.3

Returns:
The PK-Zip version (or equivalent) used to create this entry.

getVersionNeededToExtract

public UnsignedByte getVersionNeededToExtract()
Get the earliest PK-Zip version that can extract this Zip entry. The version number returned from this method is the version * 10, i.e. if this method returns 23, that corresponds to the version 2.3

Returns:
The earliest PK-Zip version that can extract this entry * 10.

getGeneralPurposeBitFlags

public ZipGeneralPurposeBitFlags getGeneralPurposeBitFlags()
Get the Zip entry's general purpose bit flags. Many of the bit flag values can be accessed directly on a Zip entry object. See isEncrypted(), ZipFileEntry.isCompressedPatchData() and isStrongEncryption().

Returns:
The Zip entry's general purpose bit flags.

isEncrypted

public boolean isEncrypted()
Is the Zip entry encrypted?

Returns:
true if the Zip entry is encrypted.
See Also:
isStrongEncryption()

isStrongEncryption

public boolean isStrongEncryption()
Is the Zip entry encrypted with strong encryption?

Returns:
true if the Zip entry is encrypted with strong encryption.
See Also:
isEncrypted()

getLastModified

public Date getLastModified()
Get the instant in time when the file or directory entity that was used to create this Zip entry was last modified. The time zone for the returned time is the time zone for the computer that built the Zip file, i.e. often not UTC.

The ExtendedTimestampExtraField, if present, has the last modified time in the UTC time zone.

Returns:
The last modification time for the Zip entry, in the time zone for the computer that built the Zip file.

getDiskNumberStart

public UnsignedShort getDiskNumberStart()
Get the number of the disk where this Zip entry begins. The first disk is number 0.

Returns:
The number of the disk where this Zip entry begins.

getExternalFileAttributes

public ZipExternalFileAttributes getExternalFileAttributes()
Get the external file attributes value.

Returns:
The external file attributes.

getExtraFields

public Collection<ZipEntryExtraField> getExtraFields()
Get a read only collection containing the Zip entry's extra fields.

Returns:
The Zip entry's extra fields, from both the local header and this entry's record in the central directory.

getExtraField

public <T> T getExtraField(Class<T> type,
                           boolean localHeader)
Get the first extra field found that matches the description.

Type Parameters:
T - The type of the extra field.
Parameters:
type - The class of the extra field, or a superclass.
localHeader - Should the extra field be from the local or the central header?
Returns:
The first extra field found that matches the description, or null if no extra field matches it.

getComment

public String getComment()
Get the Zip entry's comment.

Returns:
The Zip entry's comment, or an empty string if the comment was not set.