org.apache.commons.compress.archivers.zip
Class ZipArchiveEntry

java.lang.Object
  extended by java.util.zip.ZipEntry
      extended by org.apache.commons.compress.archivers.zip.ZipArchiveEntry
All Implemented Interfaces:
Cloneable, ArchiveEntry
Direct Known Subclasses:
JarArchiveEntry

public class ZipArchiveEntry
extends ZipEntry
implements ArchiveEntry, Cloneable

Extension that adds better handling of extra fields and provides access to the internal and external file attributes.


Field Summary
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 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
 
Fields inherited from interface org.apache.commons.compress.archivers.ArchiveEntry
SIZE_UNKNOWN
 
Constructor Summary
protected ZipArchiveEntry()
           
  ZipArchiveEntry(File inputFile, String entryName)
           
  ZipArchiveEntry(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(ZipEntry entry)
          Creates a new zip entry with fields taken from the specified zip entry.
 
Method Summary
 void addAsFirstExtraField(ZipExtraField ze)
          Adds an extra fields - replacing an already present extra field of the same type.
 void addExtraField(ZipExtraField ze)
          Adds an extra fields - 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 extra fields.
 int getInternalAttributes()
          Retrieves the internal file attributes.
 byte[] getLocalFileDataExtra()
          Retrieves the extra data for the local file data.
 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.
 int getUnixMode()
          Unix permission.
 int hashCode()
          Get the hashCode of the entry.
 boolean isDirectory()
          Is this entry a directory?
 void removeExtraField(ZipShort type)
          Remove an extra fields.
 void setCentralDirectoryExtra(byte[] b)
          Sets the central directory part of extra fields.
 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)
          Throws an Exception if extra data cannot be parsed into extra fields.
 void setExtraFields(ZipExtraField[] fields)
          Replaces all currently attached extra fields with the new array.
 void setInternalAttributes(int value)
          Sets the internal file attributes.
protected  void setName(String name)
          Set the name of the entry.
protected  void setPlatform(int platform)
          Set the platform (UNIX or FAT).
 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, getExtra, getMethod, getSize, getTime, setComment, setCompressedSize, setCrc, setMethod, setSize, setTime, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.commons.compress.archivers.ArchiveEntry
getSize
 

Field Detail

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

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

public ZipArchiveEntry(String name)
Creates a new zip entry with the specified name.

Parameters:
name - the name of the entry

ZipArchiveEntry

public ZipArchiveEntry(ZipEntry entry)
                throws ZipException
Creates a new zip entry with fields taken from the specified zip entry.

Parameters:
entry - the entry to get fields from
Throws:
ZipException - on error

ZipArchiveEntry

public ZipArchiveEntry(ZipArchiveEntry entry)
                throws ZipException
Creates a new zip entry with fields taken from the specified zip entry.

Parameters:
entry - the entry to get fields from
Throws:
ZipException - on error

ZipArchiveEntry

protected ZipArchiveEntry()

ZipArchiveEntry

public ZipArchiveEntry(File inputFile,
                       String entryName)
Method Detail

clone

public Object clone()
Overwrite clone.

Overrides:
clone in class ZipEntry
Returns:
a cloned copy of this ZipArchiveEntry

getInternalAttributes

public int getInternalAttributes()
Retrieves the internal file attributes.

Returns:
the internal file attributes

setInternalAttributes

public void setInternalAttributes(int value)
Sets the internal file attributes.

Parameters:
value - an int value

getExternalAttributes

public long getExternalAttributes()
Retrieves the external file attributes.

Returns:
the external file attributes

setExternalAttributes

public void setExternalAttributes(long value)
Sets the external file attributes.

Parameters:
value - an long value

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

getUnixMode

public int getUnixMode()
Unix permission.

Returns:
the unix permissions

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 PLATORM_UNIX will be returned.

setPlatform

protected void setPlatform(int platform)
Set the platform (UNIX or FAT).

Parameters:
platform - an int value - 0 is FAT, 3 is UNIX

setExtraFields

public void setExtraFields(ZipExtraField[] fields)
Replaces all currently attached extra fields with the new array.

Parameters:
fields - an array of extra fields

getExtraFields

public ZipExtraField[] getExtraFields()
Retrieves extra fields.

Returns:
an array of the extra fields

addExtraField

public void addExtraField(ZipExtraField ze)
Adds an extra fields - 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

addAsFirstExtraField

public void addAsFirstExtraField(ZipExtraField ze)
Adds an extra fields - replacing an already present extra field of the same type.

The new extra field will be the first one.

Parameters:
ze - an extra field

removeExtraField

public void removeExtraField(ZipShort type)
Remove an extra fields.

Parameters:
type - the type of extra field to remove

getExtraField

public ZipExtraField getExtraField(ZipShort type)
Looks up an extra field by its header id.

Returns:
null if no such field exists.

setExtra

public void setExtra(byte[] extra)
              throws RuntimeException
Throws an Exception if extra data cannot be parsed into extra fields.

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

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.


setCentralDirectoryExtra

public void setCentralDirectoryExtra(byte[] b)
Sets the central directory part of extra fields.


getLocalFileDataExtra

public byte[] getLocalFileDataExtra()
Retrieves the extra data for the local file data.

Returns:
the extra data for local file

getCentralDirectoryExtra

public byte[] getCentralDirectoryExtra()
Retrieves the extra data for the central directory.

Returns:
the central directory extra data

getName

public String getName()
Get the name of the entry.

Specified by:
getName in interface ArchiveEntry
Overrides:
getName in class ZipEntry
Returns:
the entry name

isDirectory

public boolean isDirectory()
Is this entry a directory?

Specified by:
isDirectory in interface ArchiveEntry
Overrides:
isDirectory in class ZipEntry
Returns:
true if the entry is a directory

setName

protected void setName(String name)
Set the name of the entry.

Parameters:
name - the name to use

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.

equals

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


Copyright © 2001-2009 The Apache Software Foundation. All Rights Reserved.