TrueZIP 6.8.2

de.schlichtherle.util.zip
Class ZipEntry

java.lang.Object
  extended by de.schlichtherle.util.zip.ZipEntry
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ZipEntry

public class ZipEntry
extends Object
implements Cloneable

Drop-in replacement for java.util.zip.ZipEntry. For every numeric property of this class, the default value is UNKNOWN in order to indicate an unknown state and it's permitted to set this value explicitly in order to reset the property.

Note that a ZipEntry object can be used with only one ZipFile or ZipOutputStream instance. Reusing the same ZipEntry object with a second object of these classes is an error and may result in unpredictable behaviour.

In general, this class is not thread-safe. However, it is safe to call only the getters of this class from multiple threads concurrently.

Version:
$Id: ZipEntry.java 5e709f50671d 2010/11/05 11:52:07 christian $
Author:
Christian Schlichtherle

Field Summary
private  String comment
          null if no comment field.
private  int crc
           
private static int CRC
           
private  long csize
           
static int DEFLATED
          Compression method for compressed (deflated) entries.
private  ExtraFields fields
          The map of Extra Fields.
private  short general
           
private static int GENERAL
           
private  byte init
           
private  long jTime
           
private  short method
           
private static int METHOD
           
static long MIN_DOS_TIME
          Smallest supported DOS date/time value in a ZIP file, which is January 1st, 1980 AD 00:00:00 local time.
private  String name
           
private static int NAME
           
private  long offset
          Relative Offset Of Local File Header.
private  byte platform
           
private static int PLATFORM
           
static short PLATFORM_FAT
          Windows/DOS/FAT platform.
static short PLATFORM_UNIX
          Unix platform.
private  long size
           
static int STORED
          Compression method for uncompressed (stored) entries.
static byte UNKNOWN
          The unknown value for numeric properties.
 
Constructor Summary
ZipEntry(String name)
          Creates a new zip entry with the specified name.
ZipEntry(ZipEntry blueprint)
          Creates a new zip blueprint with fields taken from the specified blueprint.
 
Method Summary
 Object clone()
           
private  ExtraField compileZip64ExtraField()
          Compiles a ZIP64 Extended Information Extra Field from the properties of this entry.
protected static long dos2javaTime(long dTime)
          Deprecated. Use DateTimeConverter.toJavaTime(long) instead.
 String getComment()
           
(package private)  int getCommentLength(String charset)
           
 long getCompressedSize()
          Returns the Compressed Size of this entry.
(package private)  long getCompressedSize32()
           
 long getCrc()
           
protected  DateTimeConverter getDateTimeConverter()
          Returns a DateTimeConverter for the conversion of Java time to DOS date/time fields and vice versa.
protected  long getDosTime()
           
 byte[] getExtra()
          Returns a protective copy of the serialized Extra Fields.
(package private)  byte[] getExtra(boolean zip64)
          Returns a protective copy of the serialized Extra Fields.
(package private)  int getExtraLength()
          Returns the length of the serialized Extra Fields in bytes.
private  ExtraFields getFields(boolean zip64)
           
(package private)  int getGeneral()
           
(package private)  boolean getGeneralBit(int index)
           
 int getMethod()
          Returns the compression method for this entry.
 String getName()
          Returns the ZIP entry name.
(package private)  int getNameLength(String charset)
           
(package private)  long getOffset()
           
(package private)  long getOffset32()
           
 short getPlatform()
           
 long getSize()
          Returns the (Uncompressed) Size of this entry.
(package private)  long getSize32()
           
 long getTime()
           
 boolean isDirectory()
          Returns true if and only if this ZIP entry represents a directory entry (i.e. end with '/').
private  boolean isInit(int index)
           
protected static long java2dosTime(long jTime)
          Deprecated. Use DateTimeConverter.toDosTime(long) instead.
private  void parseZip64ExtraField()
          Parses the properties of this entry from the ZIP64 Extended Information Extra Field, if present.
 void setComment(String comment)
           
 void setCompressedSize(long csize)
          Sets the Compressed Size of this entry.
(package private)  void setCompressedSize32(long csize)
           
private  void setCompressedSize64(long csize)
           
 void setCrc(long crc)
           
protected  void setDosTime(long dTime)
           
 void setExtra(byte[] data)
          Sets the serialized Extra Fields by making a protective copy.
private  void setExtra0(byte[] data)
           
(package private)  void setGeneral(int general)
           
(package private)  void setGeneralBit(int index, boolean bit)
           
private  void setInit(int index, boolean init)
           
 void setMethod(int method)
          Sets the compression method for this entry.
protected  void setName(String name)
          Resets the ZIP entry name.
private  void setName0(String name)
           
(package private)  void setOffset(long offset)
           
(package private)  void setOffset32(long offset)
           
private  void setOffset64(long offset)
           
 void setPlatform(short platform)
           
 void setSize(long size)
          Sets the (Uncompressed) Size of this entry.
(package private)  void setSize32(long size)
           
private  void setSize64(long size)
           
 void setTime(long jTime)
           
 String toString()
          Returns the ZIP entry name.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME

private static final int NAME
See Also:
Constant Field Values

PLATFORM

private static final int PLATFORM
See Also:
Constant Field Values

GENERAL

private static final int GENERAL
See Also:
Constant Field Values

METHOD

private static final int METHOD
See Also:
Constant Field Values

CRC

private static final int CRC
See Also:
Constant Field Values

UNKNOWN

public static final byte UNKNOWN
The unknown value for numeric properties.

See Also:
Constant Field Values

PLATFORM_FAT

public static final short PLATFORM_FAT
Windows/DOS/FAT platform.

See Also:
Constant Field Values

PLATFORM_UNIX

public static final short PLATFORM_UNIX
Unix platform.

See Also:
Constant Field Values

STORED

public static final int STORED
Compression method for uncompressed (stored) entries.

See Also:
Constant Field Values

DEFLATED

public static final int DEFLATED
Compression method for compressed (deflated) entries.

See Also:
Constant Field Values

MIN_DOS_TIME

public static final long MIN_DOS_TIME
Smallest supported DOS date/time value in a ZIP file, which is January 1st, 1980 AD 00:00:00 local time.

See Also:
Constant Field Values

init

private byte init

name

private String name

platform

private byte platform

general

private short general

method

private short method

jTime

private long jTime

crc

private int crc

csize

private long csize

size

private long size

offset

private long offset
Relative Offset Of Local File Header.


fields

private ExtraFields fields
The map of Extra Fields. Maps from Header ID [Integer] to Extra Field [ExtraField]. Should be null or may be empty if no Extra Fields are used.


comment

private String comment
null if no comment field.

Constructor Detail

ZipEntry

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


ZipEntry

public ZipEntry(ZipEntry blueprint)
Creates a new zip blueprint with fields taken from the specified blueprint.

Method Detail

clone

public Object clone()
Overrides:
clone in class Object

isInit

private boolean isInit(int index)

setInit

private void setInit(int index,
                     boolean init)

getName

public String getName()
Returns the ZIP entry name.


getNameLength

final int getNameLength(String charset)
                 throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

setName

protected void setName(String name)
Resets the ZIP entry name. This method can be called at most once and only if this entry has been created with the copy constructor or the clone() method.

Since:
TrueZIP 6.0

setName0

private void setName0(String name)

isDirectory

public boolean isDirectory()
Returns true if and only if this ZIP entry represents a directory entry (i.e. end with '/').


getPlatform

public short getPlatform()

setPlatform

public void setPlatform(short platform)

getGeneral

int getGeneral()

setGeneral

void setGeneral(int general)

getGeneralBit

final boolean getGeneralBit(int index)

setGeneralBit

final void setGeneralBit(int index,
                         boolean bit)

getMethod

public int getMethod()
Returns the compression method for this entry.

See Also:
setMethod(int), ZipOutputStream.getMethod()

setMethod

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

Throws:
RuntimeException - If method is not STORED, DEFLATED or UNKNOWN.
See Also:
getMethod(), ZipOutputStream.setMethod(int)

getDosTime

protected long getDosTime()

setDosTime

protected void setDosTime(long dTime)

getTime

public long getTime()

setTime

public void setTime(long jTime)

getDateTimeConverter

protected DateTimeConverter getDateTimeConverter()
Returns a DateTimeConverter for the conversion of Java time to DOS date/time fields and vice versa.

The implementation in the class ZipEntry returns DateTimeConverter.JAR.

Returns:
A DateTimeConverter - never null.
See Also:
DateTimeConverter

getCrc

public long getCrc()

setCrc

public void setCrc(long crc)

getCompressedSize32

long getCompressedSize32()

setCompressedSize32

void setCompressedSize32(long csize)

getCompressedSize

public long getCompressedSize()
Returns the Compressed Size of this entry.

See Also:
setCompressedSize(long)

setCompressedSize

public void setCompressedSize(long csize)
Sets the Compressed Size of this entry.

Parameters:
csize - The Compressed Size.
Throws:
RuntimeException - If csize is not in the range from 0 to ULong.MAX_VALUE (9223372036854775807L).
See Also:
getCompressedSize()

setCompressedSize64

private void setCompressedSize64(long csize)

getSize32

long getSize32()

setSize32

void setSize32(long size)

getSize

public long getSize()
Returns the (Uncompressed) Size of this entry.

See Also:
setCompressedSize(long)

setSize

public void setSize(long size)
Sets the (Uncompressed) Size of this entry.

Parameters:
size - The (Uncompressed) Size.
Throws:
RuntimeException - If size is not in the range from 0 to ULong.MAX_VALUE (9223372036854775807L).
See Also:
getCompressedSize()

setSize64

private void setSize64(long size)

getOffset32

long getOffset32()

setOffset32

void setOffset32(long offset)

getOffset

long getOffset()

setOffset

void setOffset(long offset)

setOffset64

private void setOffset64(long offset)

getExtra

public byte[] getExtra()
Returns a protective copy of the serialized Extra Fields. Note that unlike its blueprint ZipEntry.getExtra(), this method never returns null.

Returns:
A new byte array holding the serialized Extra Fields. null is never returned.

getExtra

byte[] getExtra(boolean zip64)
Returns a protective copy of the serialized Extra Fields.

Parameters:
zip64 - Whether or not a ZIP64 Extended Information Extra Field, if present, shall be included in the return data or not.
Returns:
A new byte array holding the serialized Extra Fields. null is never returned.
See Also:
getExtra()

getFields

private ExtraFields getFields(boolean zip64)

getExtraLength

final int getExtraLength()
Returns the length of the serialized Extra Fields in bytes.

Returns:
The minimum number of bytes needed to hold the serialized Extra Fields.

setExtra

public void setExtra(byte[] data)
Sets the serialized Extra Fields by making a protective copy.

Parameters:
data - The byte array holding the serialized Extra Fields. May be null.

setExtra0

private void setExtra0(byte[] data)

parseZip64ExtraField

private void parseZip64ExtraField()
Parses the properties of this entry from the ZIP64 Extended Information Extra Field, if present. The ZIP64 Extended Information Extra Field is not removed.


compileZip64ExtraField

private ExtraField compileZip64ExtraField()
Compiles a ZIP64 Extended Information Extra Field from the properties of this entry. If no ZIP64 Extended Information Extra Field is required it is removed from the collection of Extra Fields.


getComment

public String getComment()

getCommentLength

final int getCommentLength(String charset)
                    throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

setComment

public void setComment(String comment)

toString

public String toString()
Returns the ZIP entry name.

Overrides:
toString in class Object

java2dosTime

protected static long java2dosTime(long jTime)
Deprecated. Use DateTimeConverter.toDosTime(long) instead.

Refactored to {@link DateTimeConverter#JAR}.{@link DateTimeConverter#toDosTime(long) toDosTime(jTime)}.


dos2javaTime

protected static long dos2javaTime(long dTime)
Deprecated. Use DateTimeConverter.toJavaTime(long) instead.

Refactored to {@link DateTimeConverter#JAR}.{@link DateTimeConverter#toJavaTime(long) toJavaTime(dTime)}.


TrueZIP 6.8.2

Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.