ZipEntry

public class ZipEntry
extends Object implements Cloneable

java.lang.Object
   ↳ java.util.zip.ZipEntry


This class is used to represent a ZIP file entry.

Summary

Constants

int CENATT

Central directory (CEN) header internal file attributes field offset.

int CENATX

Central directory (CEN) header external file attributes field offset.

int CENCOM

Central directory (CEN) header comment length field offset.

int CENCRC

Central directory (CEN) header uncompressed file crc-32 value field offset.

int CENDSK

Central directory (CEN) header disk number start field offset.

int CENEXT

Central directory (CEN) header extra field length field offset.

int CENFLG

Central directory (CEN) header encrypt, decrypt flags field offset.

int CENHDR

Central directory (CEN) header size in bytes (including signature).

int CENHOW

Central directory (CEN) header compression method field offset.

int CENLEN

Central directory (CEN) header uncompressed size field offset.

int CENNAM

Central directory (CEN) header filename length field offset.

int CENOFF

Central directory (CEN) header LOC header offset field offset.

long CENSIG

Central directory (CEN) header signature.

int CENSIZ

Central directory (CEN) header compressed size field offset.

int CENTIM

Central directory (CEN) header modification time field offset.

int CENVEM

Central directory (CEN) header version made by field offset.

int CENVER

Central directory (CEN) header version needed to extract field offset.

int DEFLATED

Compression method for compressed (deflated) entries.

int ENDCOM

End of central directory (END) header zip file comment length field offset.

int ENDHDR

End of central directory (END) header size in bytes (including signature).

int ENDOFF

End of central directory (END) header offset for the first CEN header field offset.

long ENDSIG

End of central directory (END) header signature.

int ENDSIZ

End of central directory (END) header central directory size in bytes field offset.

int ENDSUB

End of central directory (END) header number of entries on this disk field offset.

int ENDTOT

End of central directory (END) header total number of entries field offset.

int EXTCRC

Extra local (EXT) header uncompressed file crc-32 value field offset.

int EXTHDR

Extra local (EXT) header size in bytes (including signature).

int EXTLEN

Extra local (EXT) header uncompressed size field offset.

long EXTSIG

Extra local (EXT) header signature.

int EXTSIZ

Extra local (EXT) header compressed size field offset.

int LOCCRC

Local file (LOC) header uncompressed file crc-32 value field offset.

int LOCEXT

Local file (LOC) header extra field length field offset.

int LOCFLG

Local file (LOC) header general purpose bit flag field offset.

int LOCHDR

Local file (LOC) header size in bytes (including signature).

int LOCHOW

Local file (LOC) header compression method field offset.

int LOCLEN

Local file (LOC) header uncompressed size field offset.

int LOCNAM

Local file (LOC) header filename length field offset.

long LOCSIG

Local file (LOC) header signature.

int LOCSIZ

Local file (LOC) header compressed size field offset.

int LOCTIM

Local file (LOC) header modification time field offset.

int LOCVER

Local file (LOC) header version needed to extract field offset.

int STORED

Compression method for uncompressed entries.

Public constructors

ZipEntry(String name)

Creates a new zip entry with the specified name.

ZipEntry(ZipEntry e)

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

Public methods

Object clone()

Returns a copy of this entry.

String getComment()

Returns the comment string for the entry.

long getCompressedSize()

Returns the size of the compressed entry data.

long getCrc()

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

FileTime getCreationTime()

Returns the creation time of the entry.

byte[] getExtra()

Returns the extra field data for the entry.

FileTime getLastAccessTime()

Returns the last access time of the entry.

FileTime getLastModifiedTime()

Returns the last modification time of the entry.

int getMethod()

Returns the compression method of the entry.

String getName()

Returns the name of the entry.

long getSize()

Returns the uncompressed size of the entry data.

long getTime()

Returns the last modification time of the entry.

LocalDateTime getTimeLocal()

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

int hashCode()

Returns the hash code value for this entry.

boolean isDirectory()

Returns true if this is a directory entry.

void setComment(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.

ZipEntry setCreationTime(FileTime time)

Sets the creation time of the entry.

void setExtra(byte[] extra)

Sets the optional extra field data for the entry.

ZipEntry setLastAccessTime(FileTime time)

Sets the last access time of the entry.

ZipEntry setLastModifiedTime(FileTime time)

Sets the last modification time of the entry.

void setMethod(int method)

Sets the compression method for the entry.

void setSize(long size)

Sets the uncompressed size of the entry data.

void setTime(long time)

Sets the last modification time of the entry.

void setTimeLocal(LocalDateTime time)

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

String toString()

Returns a string representation of the ZIP entry.

Inherited methods

Constants

CENATT

Added in API level 21
public static final int CENATT

Central directory (CEN) header internal file attributes field offset.

Constant Value: 36 (0x00000024)

CENATX

Added in API level 21
public static final int CENATX

Central directory (CEN) header external file attributes field offset.

Constant Value: 38 (0x00000026)

CENCOM

Added in API level 21
public static final int CENCOM

Central directory (CEN) header comment length field offset.

Constant Value: 32 (0x00000020)

CENCRC

Added in API level 21
public static final int CENCRC

Central directory (CEN) header uncompressed file crc-32 value field offset.

Constant Value: 16 (0x00000010)

CENDSK

Added in API level 21
public static final int CENDSK

Central directory (CEN) header disk number start field offset.

Constant Value: 34 (0x00000022)

CENEXT

Added in API level 21
public static final int CENEXT

Central directory (CEN) header extra field length field offset.

Constant Value: 30 (0x0000001e)

CENFLG

Added in API level 21
public static final int CENFLG

Central directory (CEN) header encrypt, decrypt flags field offset.

Constant Value: 8 (0x00000008)

CENHDR

Added in API level 21
public static final int CENHDR

Central directory (CEN) header size in bytes (including signature).

Constant Value: 46 (0x0000002e)

CENHOW

Added in API level 21
public static final int CENHOW

Central directory (CEN) header compression method field offset.

Constant Value: 10 (0x0000000a)

CENLEN

Added in API level 21
public static final int CENLEN

Central directory (CEN) header uncompressed size field offset.

Constant Value: 24 (0x00000018)

CENNAM

Added in API level 21
public static final int CENNAM

Central directory (CEN) header filename length field offset.

Constant Value: 28 (0x0000001c)

CENOFF

Added in API level 21
public static final int CENOFF

Central directory (CEN) header LOC header offset field offset.

Constant Value: 42 (0x0000002a)

CENSIG

Added in API level 21
public static final long CENSIG

Central directory (CEN) header signature.

Constant Value: 33639248 (0x0000000002014b50)

CENSIZ

Added in API level 21
public static final int CENSIZ

Central directory (CEN) header compressed size field offset.

Constant Value: 20 (0x00000014)

CENTIM

Added in API level 21
public static final int CENTIM

Central directory (CEN) header modification time field offset.

Constant Value: 12 (0x0000000c)

CENVEM

Added in API level 21
public static final int CENVEM

Central directory (CEN) header version made by field offset.

Constant Value: 4 (0x00000004)

CENVER

Added in API level 21
public static final int CENVER

Central directory (CEN) header version needed to extract field offset.

Constant Value: 6 (0x00000006)

DEFLATED

Added in API level 1
public static final int DEFLATED

Compression method for compressed (deflated) entries.

Constant Value: 8 (0x00000008)

ENDCOM

Added in API level 21
public static final int ENDCOM

End of central directory (END) header zip file comment length field offset.

Constant Value: 20 (0x00000014)

ENDHDR

Added in API level 21
public static final int ENDHDR

End of central directory (END) header size in bytes (including signature).

Constant Value: 22 (0x00000016)

ENDOFF

Added in API level 21
public static final int ENDOFF

End of central directory (END) header offset for the first CEN header field offset.

Constant Value: 16 (0x00000010)

ENDSIG

Added in API level 21
public static final long ENDSIG

End of central directory (END) header signature.

Constant Value: 101010256 (0x0000000006054b50)

ENDSIZ

Added in API level 21
public static final int ENDSIZ

End of central directory (END) header central directory size in bytes field offset.

Constant Value: 12 (0x0000000c)

ENDSUB

Added in API level 21
public static final int ENDSUB

End of central directory (END) header number of entries on this disk field offset.

Constant Value: 8 (0x00000008)

ENDTOT

Added in API level 21
public static final int ENDTOT

End of central directory (END) header total number of entries field offset.

Constant Value: 10 (0x0000000a)

EXTCRC

Added in API level 21
public static final int EXTCRC

Extra local (EXT) header uncompressed file crc-32 value field offset.

Constant Value: 4 (0x00000004)

EXTHDR

Added in API level 21
public static final int EXTHDR

Extra local (EXT) header size in bytes (including signature).

Constant Value: 16 (0x00000010)

EXTLEN

Added in API level 21
public static final int EXTLEN

Extra local (EXT) header uncompressed size field offset.

Constant Value: 12 (0x0000000c)

EXTSIG

Added in API level 21
public static final long EXTSIG

Extra local (EXT) header signature.

Constant Value: 134695760 (0x0000000008074b50)

EXTSIZ

Added in API level 21
public static final int EXTSIZ

Extra local (EXT) header compressed size field offset.

Constant Value: 8 (0x00000008)

LOCCRC

Added in API level 21
public static final int LOCCRC

Local file (LOC) header uncompressed file crc-32 value field offset.

Constant Value: 14 (0x0000000e)

LOCEXT

Added in API level 21
public static final int LOCEXT

Local file (LOC) header extra field length field offset.

Constant Value: 28 (0x0000001c)

LOCFLG

Added in API level 21
public static final int LOCFLG

Local file (LOC) header general purpose bit flag field offset.

Constant Value: 6 (0x00000006)

LOCHDR

Added in API level 21
public static final int LOCHDR

Local file (LOC) header size in bytes (including signature).

Constant Value: 30 (0x0000001e)

LOCHOW

Added in API level 21
public static final int LOCHOW

Local file (LOC) header compression method field offset.

Constant Value: 8 (0x00000008)

LOCLEN

Added in API level 21
public static final int LOCLEN

Local file (LOC) header uncompressed size field offset.

Constant Value: 22 (0x00000016)

LOCNAM

Added in API level 21
public static final int LOCNAM

Local file (LOC) header filename length field offset.

Constant Value: 26 (0x0000001a)

LOCSIG

Added in API level 21
public static final long LOCSIG

Local file (LOC) header signature.

Constant Value: 67324752 (0x0000000004034b50)

LOCSIZ

Added in API level 21
public static final int LOCSIZ

Local file (LOC) header compressed size field offset.

Constant Value: 18 (0x00000012)

LOCTIM

Added in API level 21
public static final int LOCTIM

Local file (LOC) header modification time field offset.

Constant Value: 10 (0x0000000a)

LOCVER

Added in API level 21
public static final int LOCVER

Local file (LOC) header version needed to extract field offset.

Constant Value: 4 (0x00000004)

STORED

Added in API level 1
public static final int STORED

Compression method for uncompressed entries.

Constant Value: 0 (0x00000000)

Public constructors

ZipEntry

Added in API level 1
public ZipEntry (String name)

Creates a new zip entry with the specified name.

Parameters
name String: The entry name

Throws
NullPointerException if the entry name is null
IllegalArgumentException if the entry name is longer than 0xFFFF bytes

ZipEntry

Added in API level 1
public ZipEntry (ZipEntry e)

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

Parameters
e ZipEntry: A zip Entry object

Throws
NullPointerException if the entry object is null

Public methods

clone

Added in API level 1
public Object clone ()

Returns a copy of this entry.

Returns
Object a clone of this instance.

getComment

Added in API level 1
public String getComment ()

Returns the comment string for the entry.

Returns
String the comment string for the entry, or null if none

See also:

getCompressedSize

Added in API level 1
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

getCrc

Added in API level 1
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:

getCreationTime

Added in API level 26
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

getExtra

Added in API level 1
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:

getLastAccessTime

Added in API level 26
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

getLastModifiedTime

Added in API level 26
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

getMethod

Added in API level 1
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:

getName

Added in API level 1
public String getName ()

Returns the name of the entry.

Returns
String the name of the entry

getSize

Added in API level 1
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:

getTime

Added in API level 1
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

getTimeLocal

Added in API level 35
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

hashCode

Added in API level 1
public int hashCode ()

Returns the hash code value for this entry.

Returns
int a hash code value for this object.

isDirectory

Added in API level 1
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

setComment

Added in API level 1
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:

setCompressedSize

Added in API level 1
public void setCompressedSize (long csize)

Sets the size of the compressed entry data.

Parameters
csize long: the compressed size to set

setCrc

Added in API level 1
public void setCrc (long crc)

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

Parameters
crc long: the CRC-32 value

Throws
IllegalArgumentException if the specified CRC-32 value is less than 0 or greater than 0xFFFFFFFF

See also:

setCreationTime

Added in API level 26
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

Throws
NullPointerException if the time is null

See also:

setExtra

Added in API level 1
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

Throws
IllegalArgumentException if the length of the specified extra field data is greater than 0xFFFF bytes

See also:

setLastAccessTime

Added in API level 26
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

Throws
NullPointerException if the time is null

setLastModifiedTime

Added in API level 26
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

Throws
NullPointerException if the time is null

setMethod

Added in API level 1
public void setMethod (int method)

Sets the compression method for the entry.

Parameters
method int: the compression method, either STORED or DEFLATED

Throws
IllegalArgumentException if the specified compression method is invalid

See also:

setSize

Added in API level 1
public void setSize (long size)

Sets the uncompressed size of the entry data.

Parameters
size long: the uncompressed size in bytes

Throws
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:

setTime

Added in API level 1
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 data and time.

Parameters
time long: The last modification time of the entry in milliseconds since the epoch

setTimeLocal

Added in API level 35
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

See also:

toString

Added in API level 1
public String toString ()

Returns a string representation of the ZIP entry.

Returns
String a string representation of the object.