com.mucommander.file.impl.zip.provider
Class ZipEntry

java.lang.Object
  extended by com.mucommander.file.impl.zip.provider.ZipEntry
All Implemented Interfaces:
java.lang.Cloneable

public class ZipEntry
extends java.lang.Object
implements java.lang.Cloneable

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

--------------------------------------------------------------------------------------------------------------

This class is based off the org.apache.tools.zip package of the Apache Ant project. The Ant code has been modified under the terms of the Apache License which you can find in the bundled muCommander license file. It was forked at version 1.7.0 of Ant.

Author:
Apache Ant, Maxence Bernard

Field Summary
protected static java.util.Calendar CALENDAR
          An instance of Calendar shared through all instances of this class and used for Java<->DOS time conversion
protected  java.lang.String comment
          An optional comment for this entry
protected  long compressedSize
          Compressed size of the entry data
protected  long crc
          CRC-32 checksum of the uncompressed entry data
protected  long dosTime
          Data/time of this entry, in the DOS time format
protected  com.mucommander.file.impl.zip.provider.ZipEntryInfo entryInfo
          Contains info about how this entry is stored in the zip file
protected  long externalAttributes
          External attributes (4 bytes)
protected  java.util.Vector extraFields
          List of extra fields, as ZipEntraField instances
protected  int internalAttributes
          Internal attributes (2 bytes)
protected  long javaTime
          Data/time of this entry, in the Java time format
protected  int method
          Compression method that was used for the entry data
protected static long MIN_DOS_TIME
          Smallest DOS time (Epoch 1980)
protected static int MSDOS_DIRECTORY_FLAG
          Value of the bit flag that denotes an MS-DOS directory in the external attributes
protected static int MSDOS_READ_ONLY_FLAG
          Value of the bit flag that denotes a read-only MS-DOS file in the external attributes
protected  java.lang.String name
          Name/path of this entry
protected  int platform
          Platform, part of the 'version made by' central directory field
protected static int PLATFORM_FAT
          Value of the MSDOS/OS-2 platform (FAT filesystem) used in the 'version made by' central directory field
protected static int PLATFORM_UNIX
          Value of the Unix platform used in the 'version made by' central directory field
protected  long size
          Uncompressed size of the entry data
protected static int UNIX_DIRECTORY_FLAG
          Value of the bit flag that denotes a Unix directory in the external attributes
protected static int UNIX_FILE_FLAG
          Value of the bit flag that denotes a Unix file in the external attributes
protected static int USER_WRITE_PERMISSION_BIT
          Value of the user write permission bit
 
Constructor Summary
ZipEntry()
          Creates a new Zip entry with an empty name.
ZipEntry(java.lang.String name)
          Creates a new Zip entry with the specified name.
ZipEntry(java.util.zip.ZipEntry entry)
          Creates a new Zip entry with fields taken from the specified zip entry.
 
Method Summary
 void addExtraField(ZipExtraField ze)
          Adds an extra fields, replacing any extra field of the same type previously added.
 java.lang.Object clone()
          Returns a cloned instance of this entry.
protected static long dosToJavaTime(long dosTime)
           
 boolean equals(java.lang.Object o)
          Returns true if the given object is a ZipEntry that has the same name as this one.
 byte[] getCentralDirectoryExtra()
          Returns the data of the central directory extra fields.
 java.lang.String getComment()
          Returns the comment string for the entry, or null if there is none.
 long getCompressedSize()
          Returns the size of the compressed entry data, or -1 if not known.
 long getCrc()
          Returns the CRC-32 checksum of the uncompressed entry data, or -1 if not known.
protected  long getDosTime()
          Returns this entry's date/time expressed in the DOS time format.
protected  com.mucommander.file.impl.zip.provider.ZipEntryInfo getEntryInfo()
          Returns the ZipEntryInfo instance that contains info about how this entry is stored in the zip file.
 long getExternalAttributes()
          Retrieves the external file attributes.
 ZipExtraField[] getExtraFields()
          Returns the extra fields of this entry.
 int getInternalAttributes()
          Retrieves the internal file attributes.
 byte[] getLocalFileDataExtra()
          Returns the data of the local file extra fields.
 int getMethod()
          Returns the compression method of the entry, or -1 if not specified.
 java.lang.String getName()
          Returns the name of this entry.
 int getPlatform()
          Returns the platform specification to put into the 'version made by' part of the central file header.
 long getSize()
          Returns the uncompressed size of the entry data, or -1 if not known.
 long getTime()
          Returns this entry's date/time expressed in the Java time format, i.e.
 int getUnixMode()
          Unix permission.
protected static int getUTF8Length(java.lang.String s)
           
 int hashCode()
          Returns a hash of this entry's name.
 boolean hasUnixMode()
          Returns true if this ZipEntry has Unix mode/permissions.
 boolean isDirectory()
          Returns true if the entry is a directory.
protected  boolean isValidUnsignedInt(long l)
          Returns true if the given long is a valid unsigned int value, i.e.
protected static long javaToDosTime(long javaTime)
          Converts Java time (Epoch=1970) to DOS time (Epoch=1980).
 boolean removeExtraField(ZipShort type)
          Removes the first extra field corresponding to the given type.
 void setComment(java.lang.String comment)
          Sets the optional comment string for the entry.
 void setCompressedSize(long csize)
          Sets the size of the compressed entry data.
 void setCrc(long crc)
          Sets the CRC-32 checksum of the uncompressed entry data.
protected  void setDosTime(long dosTime)
          Sets this entry's date/time to the specified one.
protected  void setEntryInfo(com.mucommander.file.impl.zip.provider.ZipEntryInfo entryInfo)
          Sets the ZipEntryInfo instance that contains info about how this entry is stored in the zip file.
 void setExternalAttributes(long value)
          Sets the external file attributes.
 void setExtra(byte[] extra)
          Throws an IllegalArgumentException if byte array cannot be parsed into extra fields.
 void setExtraFields(ZipExtraField[] fields)
          Replaces all current extra fields with the specified ones.
 void setInternalAttributes(int value)
          Sets the internal file attributes.
 void setMethod(int method)
          Sets the compression method for the entry.
protected  void setName(java.lang.String name)
          Sets the name of this entry.
protected  void setPlatform(int platform)
          Sets the platform: PLATFORM_FAT or PLATFORM_UNIX.
 void setSize(long size)
          Sets the uncompressed size of the entry data.
 void setTime(long javaTime)
          Sets this entry's date/time to the specified one.
 void setUnixMode(int mode)
          Sets Unix permissions in a way that is understood by Info-Zip's unzip command.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
Name/path of this entry


size

protected long size
Uncompressed size of the entry data


compressedSize

protected long compressedSize
Compressed size of the entry data


crc

protected long crc
CRC-32 checksum of the uncompressed entry data


dosTime

protected long dosTime
Data/time of this entry, in the DOS time format


javaTime

protected long javaTime
Data/time of this entry, in the Java time format


method

protected int method
Compression method that was used for the entry data


comment

protected java.lang.String comment
An optional comment for this entry


platform

protected int platform
Platform, part of the 'version made by' central directory field


internalAttributes

protected int internalAttributes
Internal attributes (2 bytes)


externalAttributes

protected long externalAttributes
External attributes (4 bytes)


extraFields

protected java.util.Vector extraFields
List of extra fields, as ZipEntraField instances


entryInfo

protected com.mucommander.file.impl.zip.provider.ZipEntryInfo entryInfo
Contains info about how this entry is stored in the zip file


CALENDAR

protected static final java.util.Calendar CALENDAR
An instance of Calendar shared through all instances of this class and used for Java<->DOS time conversion


MIN_DOS_TIME

protected static final long MIN_DOS_TIME
Smallest DOS time (Epoch 1980)

See Also:
Constant Field Values

UNIX_DIRECTORY_FLAG

protected static final int UNIX_DIRECTORY_FLAG
Value of the bit flag that denotes a Unix directory in the external attributes

See Also:
Constant Field Values

UNIX_FILE_FLAG

protected static final int UNIX_FILE_FLAG
Value of the bit flag that denotes a Unix file in the external attributes

See Also:
Constant Field Values

MSDOS_DIRECTORY_FLAG

protected static final int MSDOS_DIRECTORY_FLAG
Value of the bit flag that denotes an MS-DOS directory in the external attributes

See Also:
Constant Field Values

MSDOS_READ_ONLY_FLAG

protected static final int MSDOS_READ_ONLY_FLAG
Value of the bit flag that denotes a read-only MS-DOS file in the external attributes

See Also:
Constant Field Values

USER_WRITE_PERMISSION_BIT

protected static final int USER_WRITE_PERMISSION_BIT
Value of the user write permission bit

See Also:
Constant Field Values

PLATFORM_UNIX

protected static final int PLATFORM_UNIX
Value of the Unix platform used in the 'version made by' central directory field

See Also:
Constant Field Values

PLATFORM_FAT

protected static final int PLATFORM_FAT
Value of the MSDOS/OS-2 platform (FAT filesystem) used in the 'version made by' central directory field

See Also:
Constant Field Values
Constructor Detail

ZipEntry

public ZipEntry()
Creates a new Zip entry with an empty name.


ZipEntry

public ZipEntry(java.lang.String name)
Creates a new Zip entry with the specified name.

Parameters:
name - the name of the entry

ZipEntry

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

Parameters:
entry - the entry to get fields from
Throws:
java.util.zip.ZipException - on error
Method Detail

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

hasUnixMode

public boolean hasUnixMode()
Returns true if this ZipEntry has Unix mode/permissions. If that's not the case, the value returned by getUnixMode() has no meaning.

Returns:
true if this ZipEntry has Unix mode/permissions

getPlatform

public int getPlatform()
Returns the 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.

setPlatform

protected void setPlatform(int platform)
Sets the platform: PLATFORM_FAT or PLATFORM_UNIX.

Parameters:
platform - PLATFORM_FAT or PLATFORM_UNIX

setExtraFields

public void setExtraFields(ZipExtraField[] fields)
Replaces all current extra fields with the specified ones.

Parameters:
fields - an array of extra fields

getExtraFields

public ZipExtraField[] getExtraFields()
Returns the extra fields of this entry.

Returns:
the extra fields of this entry

addExtraField

public void addExtraField(ZipExtraField ze)
Adds an extra fields, replacing any extra field of the same type previously added.

Parameters:
ze - the extra field to add

removeExtraField

public boolean removeExtraField(ZipShort type)
Removes the first extra field corresponding to the given type.

Parameters:
type - the type of extra field to remove
Returns:
true if an extra field corresponding to given type was removed, false if no matching field was found

getLocalFileDataExtra

public byte[] getLocalFileDataExtra()
Returns the data of the local file extra fields. The returned byte array may be empty but never null.

Returns:
the data of the local file extra fields

getCentralDirectoryExtra

public byte[] getCentralDirectoryExtra()
Returns the data of the central directory extra fields. The returned byte array may be empty but never null.

Returns:
the data of the central directory extra fields

getName

public java.lang.String getName()
Returns the name of this entry.

Returns:
the name of this entry

setName

protected void setName(java.lang.String name)
Sets the name of this entry.

Parameters:
name - the new name for this entry

isDirectory

public boolean isDirectory()
Returns true if the entry is a directory. Directory entries are characterized by their name ending with a '/' character.

Returns:
true if the entry is a directory

getEntryInfo

protected com.mucommander.file.impl.zip.provider.ZipEntryInfo getEntryInfo()
Returns the ZipEntryInfo instance that contains info about how this entry is stored in the zip file.

Returns:
the ZipEntryInfo instance that contains info about how this entry is stored in the zip file

setEntryInfo

protected void setEntryInfo(com.mucommander.file.impl.zip.provider.ZipEntryInfo entryInfo)
Sets the ZipEntryInfo instance that contains info about how this entry is stored in the zip file.

Parameters:
entryInfo - the ZipEntryInfo instance that contains info about how this entry is stored in the zip file

getSize

public long getSize()
Returns the uncompressed size of the entry data, or -1 if not known.

Returns:
the uncompressed size of the entry data, or -1 if not known

setSize

public void setSize(long size)
Sets the uncompressed size of the entry data.

Parameters:
size - the uncompressed size in bytes
Throws:
java.lang.IllegalArgumentException - if the specified size is less than 0 or greater than 0xFFFFFFFF bytes

getCompressedSize

public long getCompressedSize()
Returns the size of the compressed entry data, or -1 if not known. In the case of a stored entry, the compressed size will be the same as the uncompressed size of the entry.

Returns:
the size of the compressed entry data, or -1 if not known

setCompressedSize

public void setCompressedSize(long csize)
Sets the size of the compressed entry data.

Parameters:
csize - the compressed size to set to

getCrc

public long getCrc()
Returns the CRC-32 checksum of the uncompressed entry data, or -1 if not known.

Returns:
the CRC-32 checksum of the uncompressed entry data, or -1 if not known

setCrc

public void setCrc(long crc)
Sets the CRC-32 checksum of the uncompressed entry data.

Parameters:
crc - the new CRC-32 value
Throws:
java.lang.IllegalArgumentException - if the specified CRC-32 value is less than 0 or greater than 0xFFFFFFFF

getTime

public long getTime()
Returns this entry's date/time expressed in the Java time format, i.e. as a number of milliseconds since the Epoch.

Returns:
this entry's date/time expressed in the Java time format

setTime

public void setTime(long javaTime)
Sets this entry's date/time to the specified one. The time must be expressed in the Java time format, i.e. as a number of milliseconds since the Epoch.

Parameters:
javaTime - the new time of this entry, expressed in the Java time format

getDosTime

protected long getDosTime()
Returns this entry's date/time expressed in the DOS time format.

Returns:
this entry's date/time expressed in the DOS time format

setDosTime

protected void setDosTime(long dosTime)
Sets this entry's date/time to the specified one. The time must be expressed in the DOS time format.

Parameters:
dosTime - the new time of this entry, expressed in the DOS time format

getMethod

public int getMethod()
Returns the compression method of the entry, or -1 if not specified.

Returns:
the compression method of the entry, or -1 if not specified

setMethod

public void setMethod(int method)
Sets the compression method for the entry.

Parameters:
method - the compression method, either ZipConstants.STORED or ZipConstants.DEFLATED
Throws:
java.lang.IllegalArgumentException - if the specified compression method is invalid

getComment

public java.lang.String getComment()
Returns the comment string for the entry, or null if there is none.

Returns:
the comment string for the entry, or null if there is none

setComment

public void setComment(java.lang.String comment)
Sets the optional comment string for the entry.

Parameters:
comment - the comment string
Throws:
java.lang.IllegalArgumentException - if the length of the specified comment string is greater than 0xFFFF bytes

setExtra

public void setExtra(byte[] extra)
              throws java.lang.IllegalArgumentException
Throws an IllegalArgumentException if byte array cannot be parsed into extra fields.

Parameters:
extra - an array of bytes to be parsed into extra fields
Throws:
java.lang.IllegalArgumentException - if the byte array cannot be parsed into extra fields

dosToJavaTime

protected static long dosToJavaTime(long dosTime)

javaToDosTime

protected static long javaToDosTime(long javaTime)
Converts Java time (Epoch=1970) to DOS time (Epoch=1980).

Parameters:
javaTime - number of milliseconds since the epoch
Returns:
time expressed in the convoluted DOS time format

getUTF8Length

protected static int getUTF8Length(java.lang.String s)

isValidUnsignedInt

protected boolean isValidUnsignedInt(long l)
Returns true if the given long is a valid unsigned int value, i.e. comprised between 0 and 2^32-1.

Parameters:
l - the long value to test
Returns:
true if the given long is a valid unsigned int value, i.e. comprised between 0 and 2^32-1

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a cloned instance of this entry.

Overrides:
clone in class java.lang.Object
Returns:
a cloned instance of this entry
Throws:
java.lang.CloneNotSupportedException - should never happen

hashCode

public int hashCode()
Returns a hash of this entry's name.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash of this entry's name

equals

public boolean equals(java.lang.Object o)
Returns true if the given object is a ZipEntry that has the same name as this one.

Overrides:
equals in class java.lang.Object
Parameters:
o - the object to test for equality
Returns:
true if the given object is a ZipEntry that has the same name as this one


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard