Top Description Fields Constructors Methods
java.util.zip

public Class ZipEntry

extends Object
implements ZipConstants, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.util.zip.ZipConstants
Known Direct Subclasses
java.util.jar.JarEntry
Static Imports
java.util.zip.ZipUtils.*, java.util.zip.ZipConstants64.*

This class is used to represent a ZIP file entry.
Author
David Connelly
Since
1.1

Field Summary

Modifier and TypeField and Description
pack-priv FileTime
pack-priv String
pack-priv long
pack-priv long
pack-priv boolean
pack-priv FileTime
public static final int
DEFLATED

Compression method for compressed (deflated) entries.

pack-priv static final long
DOSTIME_BEFORE_1980

DOS time constant for representing timestamps before 1980.

pack-priv byte[]
pack-priv int
pack-priv int
pack-priv int
pack-priv FileTime
pack-priv String
pack-priv long
public static final int
STORED

Compression method for uncompressed entries.

private static final long
UPPER_DOSTIME_BOUND

Approximately 128 years, in milliseconds (ignoring leap years etc).

pack-priv long

Constructor Summary

AccessConstructor and Description
public
ZipEntry(String
The entry name
name
)

Creates a new ZIP entry with the specified name.

public
ZipEntry(ZipEntry
A ZIP Entry object
e
)

Creates a new ZIP entry with fields taken from the specified ZIP entry.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Returns a copy of this entry.

public String

Returns:

the comment string for the entry, or null if none
getComment
()

Returns the comment string for the entry.

public long

Returns:

the size of the compressed entry data, or -1 if not known
getCompressedSize
()

Returns the size of the compressed entry data.

public long

Returns:

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

Returns the CRC-32 checksum of the uncompressed entry data.

public FileTime

Returns:

the creation time of the entry, null if not specified
getCreationTime
()

Returns the creation time of the entry.

public byte[]

Returns:

the extra field data for the entry, or null if none
getExtra
()

Returns the extra field data for the entry.

public FileTime

Returns:

The last access time of the entry, null if not specified
getLastAccessTime
()

Returns the last access time of the entry.

public FileTime

Returns:

The last modification time of the entry, null if not specified
getLastModifiedTime
()

Returns the last modification time of the entry.

public int

Returns:

the compression method of the entry, or -1 if not specified
getMethod
()

Returns the compression method of the entry.

public String

Returns:

the name of the entry
getName
()

Returns the name of the entry.

public long

Returns:

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

Returns the uncompressed size of the entry data.

public long

Returns:

The last modification time of the entry in milliseconds since the epoch, or -1 if not specified
getTime
()

Returns the last modification time of the entry.

public LocalDateTime

Returns:

The last modification time of the entry in local date-time
getTimeLocal
()

Returns the last modification time of the entry in local date-time.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code value for this entry.

public boolean

Returns:

true if this is a directory entry
isDirectory
()

Returns true if this is a directory entry.

public void
setComment(String
the comment string
comment
)

Sets the optional comment string for the entry.

public void
setCompressedSize(long
the compressed size to set
csize
)

Sets the size of the compressed entry data.

public void
setCrc(long
the CRC-32 value
crc
)

Sets the CRC-32 checksum of the uncompressed entry data.

public ZipEntry

Returns:

This ZIP entry
setCreationTime
(FileTime
The creation time of the entry
time
)

Sets the creation time of the entry.

public void
setExtra(byte[]
The extra field data bytes
extra
)

Sets the optional extra field data for the entry.

pack-priv void
setExtra0(byte[]
the extra field data bytes
extra
,
boolean
if true, set size and csize from ZIP64 fields if present
doZIP64
,
boolean
true if setting the extra field for a LOC, false if for a CEN
isLOC
)

Sets the optional extra field data for the entry.

public ZipEntry

Returns:

This ZIP entry
setLastAccessTime
(FileTime
The last access time of the entry
time
)

Sets the last access time of the entry.

public ZipEntry

Returns:

This ZIP entry
setLastModifiedTime
(FileTime
The last modification time of the entry
time
)

Sets the last modification time of the entry.

public void
setMethod(int
the compression method, either STORED or DEFLATED
method
)

Sets the compression method for the entry.

public void
setSize(long
the uncompressed size in bytes
size
)

Sets the uncompressed size of the entry data.

public void
setTime(long
The last modification time of the entry in milliseconds since the epoch
time
)

Sets the last modification time of the entry.

public void
setTimeLocal(LocalDateTime
The last modification time of the entry in local date-time
time
)

Sets the last modification time of the entry in local date-time.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the ZIP entry.

Inherited from java.lang.Object:
equalsfinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

atimeback to summary
pack-priv FileTime atime
commentback to summary
pack-priv String comment
crcback to summary
pack-priv long crc
csizeback to summary
pack-priv long csize
csizeSetback to summary
pack-priv boolean csizeSet
ctimeback to summary
pack-priv FileTime ctime
DEFLATEDback to summary
public static final int DEFLATED

Compression method for compressed (deflated) entries.

DOSTIME_BEFORE_1980back to summary
pack-priv static final long DOSTIME_BEFORE_1980

DOS time constant for representing timestamps before 1980.

extraback to summary
pack-priv byte[] extra
extraAttributesback to summary
pack-priv int extraAttributes
flagback to summary
pack-priv int flag
methodback to summary
pack-priv int method
mtimeback to summary
pack-priv FileTime mtime
nameback to summary
pack-priv String name
sizeback to summary
pack-priv long size
STOREDback to summary
public static final int STORED

Compression method for uncompressed entries.

UPPER_DOSTIME_BOUNDback to summary
private static final long UPPER_DOSTIME_BOUND

Approximately 128 years, in milliseconds (ignoring leap years etc). This establish an approximate high-bound value for DOS times in milliseconds since epoch, used to enable an efficient but sufficient bounds check to avoid generating extended last modified time entries. Calculating the exact number is locale dependent, would require loading TimeZone data eagerly, and would make little practical sense. Since DOS times theoretically go to 2107 - with compatibility not guaranteed after 2099 - setting this to a time that is before but near 2099 should be sufficient.

xdostimeback to summary
pack-priv long xdostime

Constructor Detail

ZipEntryback to summary
public ZipEntry(String name)

Creates a new ZIP entry with the specified name.

Parameters
name:String

The entry name

Exceptions
NullPointerException:
if the entry name is null
IllegalArgumentException:
if the entry name is longer than 0xFFFF bytes
ZipEntryback to summary
public ZipEntry(ZipEntry e)

Creates a new ZIP entry with fields taken from the specified ZIP entry.

Parameters
e:ZipEntry

A ZIP Entry object

Exceptions
NullPointerException:
if the entry object is null

Method Detail

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Returns a copy of this entry.

Returns:Object

Doc from java.lang.Object.clone.

a clone of this instance.

getCommentback to summary
public String getComment()

Returns the comment string for the entry.

Returns:String

the comment string for the entry, or null if none

See Also
setComment(String)
getCompressedSizeback to summary
public long getCompressedSize()

Returns the size of the compressed entry data.

In the case of a stored entry, the compressed size will be the same as the uncompressed size of the entry.

Returns:long

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

See Also
setCompressedSize(long)
getCrcback to summary
public long getCrc()

Returns the CRC-32 checksum of the uncompressed entry data.

Returns:long

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

See Also
setCrc(long)
getCreationTimeback to summary
public FileTime getCreationTime()

Returns the creation time of the entry.

The creation time is from the extended timestamp fields of entry's optional extra data when read from a ZIP file or ZIP file formatted stream.

Returns:FileTime

the creation time of the entry, null if not specified

Since
1.8
See Also
setCreationTime(FileTime)
getExtraback to summary
public byte[] getExtra()

Returns the extra field data for the entry.

Returns:byte[]

the extra field data for the entry, or null if none

See Also
setExtra(byte[])
getLastAccessTimeback to summary
public FileTime getLastAccessTime()

Returns the last access time of the entry.

The last access time is from the extended timestamp fields of entry's optional extra data when read from a ZIP file or ZIP file formatted stream.

Returns:FileTime

The last access time of the entry, null if not specified

Since
1.8
See Also
setLastAccessTime(FileTime)
getLastModifiedTimeback to summary
public FileTime getLastModifiedTime()

Returns the last modification time of the entry.

If the entry is read from a ZIP file or ZIP file formatted input stream, this is the last modification time from the zip file entry's optional extra data if the extended timestamp fields are present. Otherwise the last modification time is read from the entry's date and time fields, the default TimeZone is used to convert the standard MS-DOS formatted date and time to the epoch time.

Returns:FileTime

The last modification time of the entry, null if not specified

Since
1.8
See Also
setLastModifiedTime(FileTime)
getMethodback to summary
public int getMethod()

Returns the compression method of the entry.

Returns:int

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

See Also
setMethod(int)
getNameback to summary
public String getName()

Returns the name of the entry.

Returns:String

the name of the entry

getSizeback to summary
public long getSize()

Returns the uncompressed size of the entry data.

Returns:long

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

See Also
setSize(long)
getTimeback to summary
public long getTime()

Returns the last modification time of the entry.

If the entry is read from a ZIP file or ZIP file formatted input stream, this is the last modification time from the date and time fields of the ZIP file entry. The default TimeZone is used to convert the standard MS-DOS formatted date and time to the epoch time.

Returns:long

The last modification time of the entry in milliseconds since the epoch, or -1 if not specified

See Also
setTime(long), setLastModifiedTime(FileTime)
getTimeLocalback to summary
public LocalDateTime getTimeLocal()

Returns the last modification time of the entry in local date-time.

If the entry is read from a ZIP file or ZIP file formatted input stream, this is the last modification time from the zip file entry's optional extra data if the extended timestamp fields are present. Otherwise, the last modification time is read from entry's standard MS-DOS formatted date and time fields.

The system default TimeZone is used to convert the UTC time to local date-time.

Returns:LocalDateTime

The last modification time of the entry in local date-time

Since
9
See Also
setTimeLocal(LocalDateTime)
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns the hash code value for this entry.

Returns:int

Doc from java.lang.Object.hashCode.

a hash code value for this object

isDirectoryback to summary
public boolean isDirectory()

Returns true if this is a directory entry. A directory entry is defined to be one whose name ends with a '/'.

Returns:boolean

true if this is a directory entry

setCommentback to summary
public void setComment(String comment)

Sets the optional comment string for the entry.

ZIP entry comments have maximum length of 0xffff. If the length of the specified comment string is greater than 0xFFFF bytes after encoding, only the first 0xFFFF bytes are output to the ZIP file entry.

Parameters
comment:String

the comment string

See Also
getComment()
setCompressedSizeback to summary
public void setCompressedSize(long csize)

Sets the size of the compressed entry data.

Parameters
csize:long

the compressed size to set

See Also
getCompressedSize()
setCrcback to summary
public void setCrc(long crc)

Sets the CRC-32 checksum of the uncompressed entry data.

Parameters
crc:long

the CRC-32 value

Exceptions
IllegalArgumentException:
if the specified CRC-32 value is less than 0 or greater than 0xFFFFFFFF
See Also
getCrc()
setCreationTimeback to summary
public ZipEntry setCreationTime(FileTime time)

Sets the creation time of the entry.

If set, the creation time will be stored into the extended timestamp fields of entry's optional extra data, when output to a ZIP file or ZIP file formatted stream.

Parameters
time:FileTime

The creation time of the entry

Returns:ZipEntry

This ZIP entry

Exceptions
NullPointerException:
if the time is null
Since
1.8
See Also
getCreationTime()
setExtraback to summary
public void setExtra(byte[] extra)

Sets the optional extra field data for the entry.

Invoking this method may change this entry's last modification time, last access time and creation time, if the extra field data includes the extensible timestamp fields, such as NTFS tag 0x0001 or Info-ZIP Extended Timestamp, as specified in Info-ZIP Application Note 970311.

Parameters
extra:byte[]

The extra field data bytes

Exceptions
IllegalArgumentException:
if the length of the specified extra field data is greater than 0xFFFF bytes
See Also
getExtra()
setExtra0back to summary
pack-priv void setExtra0(byte[] extra, boolean doZIP64, boolean isLOC)

Sets the optional extra field data for the entry.

Parameters
extra:byte[]

the extra field data bytes

doZIP64:boolean

if true, set size and csize from ZIP64 fields if present

isLOC:boolean

true if setting the extra field for a LOC, false if for a CEN

setLastAccessTimeback to summary
public ZipEntry setLastAccessTime(FileTime time)

Sets the last access time of the entry.

If set, the last access time will be stored into the extended timestamp fields of entry's optional extra data, when output to a ZIP file or ZIP file formatted stream.

Parameters
time:FileTime

The last access time of the entry

Returns:ZipEntry

This ZIP entry

Exceptions
NullPointerException:
if the time is null
Since
1.8
See Also
getLastAccessTime()
setLastModifiedTimeback to summary
public ZipEntry setLastModifiedTime(FileTime time)

Sets the last modification time of the entry.

When output to a ZIP file or ZIP file formatted output stream the last modification time set by this method will be stored into ZIP file entry's date and time fields in standard MS-DOS date and time format), and the extended timestamp fields in optional extra data in UTC time.

Parameters
time:FileTime

The last modification time of the entry

Returns:ZipEntry

This ZIP entry

Exceptions
NullPointerException:
if the time is null
Since
1.8
See Also
getLastModifiedTime()
setMethodback to summary
public void setMethod(int method)

Sets the compression method for the entry.

Parameters
method:int

the compression method, either STORED or DEFLATED

Exceptions
IllegalArgumentException:
if the specified compression method is invalid
See Also
getMethod()
setSizeback to summary
public void setSize(long size)

Sets the uncompressed size of the entry data.

Parameters
size:long

the uncompressed size in bytes

Exceptions
IllegalArgumentException:
if the specified size is less than 0, is greater than 0xFFFFFFFF when ZIP64 format is not supported, or is less than 0 when ZIP64 is supported
See Also
getSize()
setTimeback to summary
public void setTime(long time)

Sets the last modification time of the entry.

If the entry is output to a ZIP file or ZIP file formatted output stream the last modification time set by this method will be stored into the date and time fields of the ZIP file entry and encoded in standard MS-DOS date and time format. The default TimeZone is used to convert the epoch time to the MS-DOS date and time.

Parameters
time:long

The last modification time of the entry in milliseconds since the epoch

See Also
getTime(), getLastModifiedTime()
setTimeLocalback to summary
public void setTimeLocal(LocalDateTime time)

Sets the last modification time of the entry in local date-time.

If the entry is output to a ZIP file or ZIP file formatted output stream the last modification time set by this method will be stored into the date and time fields of the ZIP file entry and encoded in standard MS-DOS date and time format. If the date-time set is out of the range of the standard MS-DOS date and time format, the time will also be stored into ZIP file entry's extended timestamp fields in optional extra data in UTC time. The system default TimeZone is used to convert the local date-time to UTC time.

LocalDateTime uses a precision of nanoseconds, whereas this class uses a precision of milliseconds. The conversion will truncate any excess precision information as though the amount in nanoseconds was subject to integer division by one million.

Parameters
time:LocalDateTime

The last modification time of the entry in local date-time

Exceptions
NullPointerException:
if time is null
Since
9
See Also
getTimeLocal()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the ZIP entry.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object