Package org.apache.tools.zip

# Class ZipEntry

java.lang.Object
java.util.zip.ZipEntry
org.apache.tools.zip.ZipEntry

All Implemented Interfaces:
  `Cloneable`

public class ZipEntry extends ZipEntry implements Cloneable
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. Older versions would have thrown an exception if any attempt was made to read or write extra data not conforming to the recommendation.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  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`

  ### Fields inherited from class java.util.zip.ZipEntry

  `DEFLATED, STORED`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `ZipEntry()`
  ``
  `ZipEntry​(File inputFile, String entryName)`
  Creates a new zip entry taking some information from the given file and using the provided name.
  ``
  `ZipEntry​(String name)`
  Creates a new zip entry with the specified name.
  ``
  `ZipEntry​(ZipEntry entry)`
  Creates a new zip entry with fields taken from the specified zip entry.
  ``
  `ZipEntry​(ZipEntry entry)`
  Creates a new zip entry with fields taken from the specified zip entry.

- ## Method Summary

  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.
  `Object`
  `clone()`
  Overwrite clone.
  `boolean`
  `equals​(Object obj)`
  `byte[]`
  `getCentralDirectoryExtra()`
  Retrieves the extra data for the central directory.
  `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.
  `Date`
  `getLastModifiedDate()`
  `byte[]`
  `getLocalFileDataExtra()`
  Retrieves the extra data for the local file data.
  `int`
  `getMethod()`
  Returns the compression method of this entry, or -1 if the compression method has not been specified.
  `String`
  `getName()`
  Get the name of the entry.
  `int`
  `getPlatform()`
  Platform specification to put into the "version made by" part of the central file header.
  `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.
  `int`
  `hashCode()`
  Get the hashCode of the entry.
  `boolean`
  `isDirectory()`
  Is this entry a directory?
  `void`
  `removeExtraField​(ZipShort type)`
  Remove an extra field.
  `void`
  `removeUnparseableExtraFieldData()`
  Removes unparseable extra field data.
  `void`
  `setCentralDirectoryExtra​(byte[] b)`
  Sets the central directory part of extra fields.
  `void`
  `setComprSize​(long size)`
  Deprecated.
  since 1.7.
  `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.
  `void`
  `setMethod​(int method)`
  Sets the compression method of this entry.
  `protected void`
  `setName​(String name)`
  Set the name of the entry.
  `protected void`
  `setName​(String name, byte[] rawName)`
  Sets the name using the raw bytes and the string created from it by guessing or using the configured encoding.
  `protected void`
  `setPlatform​(int platform)`
  Set the platform (UNIX or FAT).
  `void`
  `setSize​(long size)`
  Sets the uncompressed size of the entry data.
  `void`
  `setUnixMode​(int mode)`
  Sets Unix permissions in a way that is understood by Info-Zip's unzip command.

  ### Methods inherited from class java.util.zip.ZipEntry

  `getComment, getCompressedSize, getCrc, getCreationTime, getExtra, getLastAccessTime, getLastModifiedTime, getTime, getTimeLocal, setComment, setCompressedSize, setCrc, setCreationTime, setLastAccessTime, setLastModifiedTime, setTime, setTimeLocal, toString`

  ### Methods inherited from class java.lang.Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### 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

  - ### LOCSIG

    static final long LOCSIG
    See Also:
      Constant Field Values

  - ### EXTSIG

    static final long EXTSIG
    See Also:
      Constant Field Values

  - ### CENSIG

    static final long CENSIG
    See Also:
      Constant Field Values

  - ### ENDSIG

    static final long ENDSIG
    See Also:
      Constant Field Values

  - ### LOCHDR

    static final int LOCHDR
    See Also:
      Constant Field Values

  - ### EXTHDR

    static final int EXTHDR
    See Also:
      Constant Field Values

  - ### CENHDR

    static final int CENHDR
    See Also:
      Constant Field Values

  - ### ENDHDR

    static final int ENDHDR
    See Also:
      Constant Field Values

  - ### LOCVER

    static final int LOCVER
    See Also:
      Constant Field Values

  - ### LOCFLG

    static final int LOCFLG
    See Also:
      Constant Field Values

  - ### LOCHOW

    static final int LOCHOW
    See Also:
      Constant Field Values

  - ### LOCTIM

    static final int LOCTIM
    See Also:
      Constant Field Values

  - ### LOCCRC

    static final int LOCCRC
    See Also:
      Constant Field Values

  - ### LOCSIZ

    static final int LOCSIZ
    See Also:
      Constant Field Values

  - ### LOCLEN

    static final int LOCLEN
    See Also:
      Constant Field Values

  - ### LOCNAM

    static final int LOCNAM
    See Also:
      Constant Field Values

  - ### LOCEXT

    static final int LOCEXT
    See Also:
      Constant Field Values

  - ### EXTCRC

    static final int EXTCRC
    See Also:
      Constant Field Values

  - ### EXTSIZ

    static final int EXTSIZ
    See Also:
      Constant Field Values

  - ### EXTLEN

    static final int EXTLEN
    See Also:
      Constant Field Values

  - ### CENVEM

    static final int CENVEM
    See Also:
      Constant Field Values

  - ### CENVER

    static final int CENVER
    See Also:
      Constant Field Values

  - ### CENFLG

    static final int CENFLG
    See Also:
      Constant Field Values

  - ### CENHOW

    static final int CENHOW
    See Also:
      Constant Field Values

  - ### CENTIM

    static final int CENTIM
    See Also:
      Constant Field Values

  - ### CENCRC

    static final int CENCRC
    See Also:
      Constant Field Values

  - ### CENSIZ

    static final int CENSIZ
    See Also:
      Constant Field Values

  - ### CENLEN

    static final int CENLEN
    See Also:
      Constant Field Values

  - ### CENNAM

    static final int CENNAM
    See Also:
      Constant Field Values

  - ### CENEXT

    static final int CENEXT
    See Also:
      Constant Field Values

  - ### CENCOM

    static final int CENCOM
    See Also:
      Constant Field Values

  - ### CENDSK

    static final int CENDSK
    See Also:
      Constant Field Values

  - ### CENATT

    static final int CENATT
    See Also:
      Constant Field Values

  - ### CENATX

    static final int CENATX
    See Also:
      Constant Field Values

  - ### CENOFF

    static final int CENOFF
    See Also:
      Constant Field Values

  - ### ENDSUB

    static final int ENDSUB
    See Also:
      Constant Field Values

  - ### ENDTOT

    static final int ENDTOT
    See Also:
      Constant Field Values

  - ### ENDSIZ

    static final int ENDSIZ
    See Also:
      Constant Field Values

  - ### ENDOFF

    static final int ENDOFF
    See Also:
      Constant Field Values

  - ### ENDCOM

    static final int ENDCOM
    See Also:
      Constant Field Values

- ## Constructor Details

  - ### ZipEntry

    public ZipEntry​(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
    Since:
      1.1

  - ### ZipEntry

    public ZipEntry​(ZipEntry entry) throws 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:
      `ZipException` - on error
    Since:
      1.1

  - ### ZipEntry

    public ZipEntry​(ZipEntry entry) throws 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:
      `ZipException` - on error
    Since:
      1.1

  - ### ZipEntry

    protected ZipEntry()
    Since:
      1.9

  - ### ZipEntry

    public ZipEntry​(File inputFile, 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
      `entryName` - String

- ## Method Details

  - ### clone

    public Object clone()
    Overwrite clone.
    Overrides:
      `clone` in class `ZipEntry`
    Returns:
      a cloned copy of this ZipEntry
    Since:
      1.1

  - ### getMethod

    public int getMethod()
    Returns the compression method of this entry, or -1 if the compression method has not been specified.
    Overrides:
      `getMethod` in class `ZipEntry`
    Returns:
      compression method

  - ### setMethod

    public void setMethod​(int method)
    Sets the compression method of this entry.
    Overrides:
      `setMethod` in class `ZipEntry`
    Parameters:
      `method` - compression method

  - ### getInternalAttributes

    public int getInternalAttributes()
    Retrieves the internal file attributes.
    Returns:
      the internal file attributes
    Since:
      1.1

  - ### setInternalAttributes

    public void setInternalAttributes​(int value)
    Sets the internal file attributes.
    Parameters:
      `value` - an `int` value
    Since:
      1.1

  - ### getExternalAttributes

    public long getExternalAttributes()
    Retrieves the external file attributes.
    Returns:
      the external file attributes
    Since:
      1.1

  - ### setExternalAttributes

    public void setExternalAttributes​(long value)
    Sets the external file attributes.
    Parameters:
      `value` - an `long` value
    Since:
      1.1

  - ### setUnixMode

    public void setUnixMode​(int mode)
    Sets Unix permissions in a way that is understood by Info-Zip's unzip command.
    Parameters:
      `mode` - an `int` value
    Since:
      Ant 1.5.2

  - ### getUnixMode

    public int getUnixMode()
    Unix permission.
    Returns:
      the unix permissions
    Since:
      Ant 1.6

  - ### 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.
    Since:
      Ant 1.5.2

  - ### setPlatform

    protected void setPlatform​(int platform)
    Set the platform (UNIX or FAT).
    Parameters:
      `platform` - an `int` value - 0 is FAT, 3 is UNIX
    Since:
      1.9

  - ### setExtraFields

    public void setExtraFields​(ZipExtraField[] fields)
    Replaces all currently attached extra fields with the new array.
    Parameters:
      `fields` - an array of extra fields
    Since:
      1.1

  - ### getExtraFields

    public ZipExtraField[] getExtraFields()
    Retrieves all extra fields that have been parsed successfully.
    Returns:
      an array of the extra fields

  - ### getExtraFields

    public ZipExtraField[] getExtraFields​(boolean includeUnparseable)
    Retrieves extra fields.
    Parameters:
      `includeUnparseable` - whether to also return unparseable extra fields as `UnparseableExtraFieldData` if such data exists.
    Returns:
      an array of the extra fields
    Since:
      1.1

  - ### 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
    Since:
      1.1

  - ### 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
    Since:
      1.1

  - ### removeExtraField

    public void removeExtraField​(ZipShort type)
    Remove an extra field.
    Parameters:
      `type` - the type of extra field to remove
    Since:
      1.1

  - ### removeUnparseableExtraFieldData

    public void removeUnparseableExtraFieldData()
    Removes unparseable extra field data.

  - ### getExtraField

    public ZipExtraField getExtraField​(ZipShort type)
    Looks up an extra field by its header id.
    Parameters:
      `type` - ZipShort
    Returns:
      null if no such field exists.

  - ### getUnparseableExtraFieldData

    public UnparseableExtraFieldData getUnparseableExtraFieldData()
    Looks up extra field data that couldn't be parsed correctly.
    Returns:
      null if no such field exists.

  - ### setExtra

    public void setExtra​(byte[] extra) throws RuntimeException
    Parses the given bytes as extra field data and consumes any unparseable data as an `UnparseableExtraFieldData` instance.
    Overrides:
      `setExtra` in class `ZipEntry`
    Parameters:
      `extra` - an array of bytes to be parsed into extra fields
    Throws:
      `RuntimeException` - if the bytes cannot be parsed
      `RuntimeException` - on error
    Since:
      1.1

  - ### setExtra

    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.
    Since:
      1.1

  - ### setCentralDirectoryExtra

    public void setCentralDirectoryExtra​(byte[] b)
    Sets the central directory part of extra fields.
    Parameters:
      `b` - boolean

  - ### getLocalFileDataExtra

    public byte[] getLocalFileDataExtra()
    Retrieves the extra data for the local file data.
    Returns:
      the extra data for local file
    Since:
      1.1

  - ### getCentralDirectoryExtra

    public byte[] getCentralDirectoryExtra()
    Retrieves the extra data for the central directory.
    Returns:
      the central directory extra data
    Since:
      1.1

  - ### setComprSize

    @Deprecated public void setComprSize​(long size)
    Deprecated.
    since 1.7. Use setCompressedSize directly.
    Make this class work in JDK 1.1 like a 1.2 class.

    This either stores the size for later usage or invokes setCompressedSize via reflection.

    Parameters:
      `size` - the size to use
    Since:
      1.2

  - ### getName

    public String getName()
    Get the name of the entry.
    Overrides:
      `getName` in class `ZipEntry`
    Returns:
      the entry name
    Since:
      1.9

  - ### isDirectory

    public boolean isDirectory()
    Is this entry a directory?
    Overrides:
      `isDirectory` in class `ZipEntry`
    Returns:
      true if the entry is a directory
    Since:
      1.10

  - ### setName

    protected void setName​(String name)
    Set the name of the entry.
    Parameters:
      `name` - the name to use

  - ### getSize

    public long getSize()
    Gets the uncompressed size of the entry data.
    Overrides:
      `getSize` in class `ZipEntry`
    Returns:
      the entry size

  - ### setSize

    public void setSize​(long size)
    Sets the uncompressed size of the entry data.
    Overrides:
      `setSize` in class `ZipEntry`
    Parameters:
      `size` - the uncompressed size in bytes
    Throws:
      `IllegalArgumentException` - if the specified size is less than 0

  - ### setName

    protected void setName​(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 encoding
      `rawName` - the bytes originally read as name from the archive

  - ### 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:
      byte[]

  - ### hashCode

    public int hashCode()
    Get the hashCode of the entry. This uses the name as the hashcode.
    Overrides:
      `hashCode` in class `ZipEntry`
    Returns:
      a hashcode.
    Since:
      Ant 1.7

  - ### getGeneralPurposeBit

    public GeneralPurposeBit getGeneralPurposeBit()
    The "general purpose bit" field.
    Returns:
      GeneralPurposeBit

  - ### setGeneralPurposeBit

    public void setGeneralPurposeBit​(GeneralPurposeBit b)
    The "general purpose bit" field.
    Parameters:
      `b` - GeneralPurposeBit

  - ### getLastModifiedDate

    public Date getLastModifiedDate()

  - ### equals

    public boolean equals​(Object obj)
    Overrides:
      `equals` in class `Object`