Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ZipEntry

public class ZipEntry
extends Object implements Cloneable

java.lang.Object
   ↳ java.util.zip.ZipEntry
Known Direct Subclasses


An entry within a zip file. An entry has attributes such as its name (which is actually a path) and the uncompressed size of the corresponding data. An entry does not contain the data itself, but can be used as a key with getInputStream(ZipEntry). The class documentation for ZipInputStream and ZipOutputStream shows how ZipEntry is used in conjunction with those two classes.

Summary

Constants

int CENATT

int CENATX

int CENCOM

int CENCRC

int CENDSK

int CENEXT

int CENFLG

int CENHDR

int CENHOW

int CENLEN

int CENNAM

int CENOFF

long CENSIG

int CENSIZ

int CENTIM

int CENVEM

int CENVER

int DEFLATED

Zip entry state: Deflated.

int ENDCOM

int ENDHDR

int ENDOFF

long ENDSIG

int ENDSIZ

int ENDSUB

int ENDTOT

int EXTCRC

int EXTHDR

int EXTLEN

long EXTSIG

int EXTSIZ

int LOCCRC

int LOCEXT

int LOCFLG

int LOCHDR

int LOCHOW

int LOCLEN

int LOCNAM

long LOCSIG

int LOCSIZ

int LOCTIM

int LOCVER

int STORED

Zip entry state: Stored.

Public constructors

ZipEntry(String name)

Constructs a new ZipEntry with the specified name.

ZipEntry(ZipEntry ze)

Constructs a new ZipEntry using the values obtained from ze.

Public methods

Object clone()

Returns a deep copy of this zip entry.

String getComment()

Returns the comment for this ZipEntry, or null if there is no comment.

long getCompressedSize()

Gets the compressed size of this ZipEntry.

long getCrc()

Gets the checksum for this ZipEntry.

byte[] getExtra()

Gets the extra information for this ZipEntry.

int getMethod()

Gets the compression method for this ZipEntry.

String getName()

Gets the name of this ZipEntry.

long getSize()

Gets the uncompressed size of this ZipEntry.

long getTime()

Gets the last modification time of this ZipEntry.

int hashCode()

Returns the hash code for this ZipEntry.

boolean isDirectory()

Determine whether or not this ZipEntry is a directory.

void setComment(String comment)

Sets the comment for this ZipEntry.

void setCompressedSize(long value)

Sets the compressed size for this ZipEntry.

void setCrc(long value)

Sets the checksum for this ZipEntry.

void setExtra(byte[] data)

Sets the extra information for this ZipEntry.

void setMethod(int value)

Sets the compression method for this entry to either DEFLATED or STORED.

void setSize(long value)

Sets the uncompressed size of this ZipEntry.

void setTime(long value)

Sets the modification time of this ZipEntry.

String toString()

Returns the string representation of this ZipEntry.

Inherited methods

From class java.lang.Object

Constants

CENATT

Added in API level 21
int CENATT

Constant Value: 36 (0x00000024)

CENATX

Added in API level 21
int CENATX

Constant Value: 38 (0x00000026)

CENCOM

Added in API level 21
int CENCOM

Constant Value: 32 (0x00000020)

CENCRC

Added in API level 21
int CENCRC

Constant Value: 16 (0x00000010)

CENDSK

Added in API level 21
int CENDSK

Constant Value: 34 (0x00000022)

CENEXT

Added in API level 21
int CENEXT

Constant Value: 30 (0x0000001e)

CENFLG

Added in API level 21
int CENFLG

Constant Value: 8 (0x00000008)

CENHDR

Added in API level 21
int CENHDR

Constant Value: 46 (0x0000002e)

CENHOW

Added in API level 21
int CENHOW

Constant Value: 10 (0x0000000a)

CENLEN

Added in API level 21
int CENLEN

Constant Value: 24 (0x00000018)

CENNAM

Added in API level 21
int CENNAM

Constant Value: 28 (0x0000001c)

CENOFF

Added in API level 21
int CENOFF

Constant Value: 42 (0x0000002a)

CENSIG

Added in API level 21
long CENSIG

Constant Value: 33639248 (0x0000000002014b50)

CENSIZ

Added in API level 21
int CENSIZ

Constant Value: 20 (0x00000014)

CENTIM

Added in API level 21
int CENTIM

Constant Value: 12 (0x0000000c)

CENVEM

Added in API level 21
int CENVEM

Constant Value: 4 (0x00000004)

CENVER

Added in API level 21
int CENVER

Constant Value: 6 (0x00000006)

DEFLATED

Added in API level 1
int DEFLATED

Zip entry state: Deflated.

Constant Value: 8 (0x00000008)

ENDCOM

Added in API level 21
int ENDCOM

Constant Value: 20 (0x00000014)

ENDHDR

Added in API level 21
int ENDHDR

Constant Value: 22 (0x00000016)

ENDOFF

Added in API level 21
int ENDOFF

Constant Value: 16 (0x00000010)

ENDSIG

Added in API level 21
long ENDSIG

Constant Value: 101010256 (0x0000000006054b50)

ENDSIZ

Added in API level 21
int ENDSIZ

Constant Value: 12 (0x0000000c)

ENDSUB

Added in API level 21
int ENDSUB

Constant Value: 8 (0x00000008)

ENDTOT

Added in API level 21
int ENDTOT

Constant Value: 10 (0x0000000a)

EXTCRC

Added in API level 21
int EXTCRC

Constant Value: 4 (0x00000004)

EXTHDR

Added in API level 21
int EXTHDR

Constant Value: 16 (0x00000010)

EXTLEN

Added in API level 21
int EXTLEN

Constant Value: 12 (0x0000000c)

EXTSIG

Added in API level 21
long EXTSIG

Constant Value: 134695760 (0x0000000008074b50)

EXTSIZ

Added in API level 21
int EXTSIZ

Constant Value: 8 (0x00000008)

LOCCRC

Added in API level 21
int LOCCRC

Constant Value: 14 (0x0000000e)

LOCEXT

Added in API level 21
int LOCEXT

Constant Value: 28 (0x0000001c)

LOCFLG

Added in API level 21
int LOCFLG

Constant Value: 6 (0x00000006)

LOCHDR

Added in API level 21
int LOCHDR

Constant Value: 30 (0x0000001e)

LOCHOW

Added in API level 21
int LOCHOW

Constant Value: 8 (0x00000008)

LOCLEN

Added in API level 21
int LOCLEN

Constant Value: 22 (0x00000016)

LOCNAM

Added in API level 21
int LOCNAM

Constant Value: 26 (0x0000001a)

LOCSIG

Added in API level 21
long LOCSIG

Constant Value: 67324752 (0x0000000004034b50)

LOCSIZ

Added in API level 21
int LOCSIZ

Constant Value: 18 (0x00000012)

LOCTIM

Added in API level 21
int LOCTIM

Constant Value: 10 (0x0000000a)

LOCVER

Added in API level 21
int LOCVER

Constant Value: 4 (0x00000004)

STORED

Added in API level 1
int STORED

Zip entry state: Stored.

Constant Value: 0 (0x00000000)

Public constructors

ZipEntry

Added in API level 1
ZipEntry (String name)

Constructs a new ZipEntry with the specified name. The name is actually a path, and may contain / characters.

Parameters
name String
Throws
IllegalArgumentException if the name length is outside the range (> 0xFFFF).

ZipEntry

Added in API level 1
ZipEntry (ZipEntry ze)

Constructs a new ZipEntry using the values obtained from ze.

Parameters
ze ZipEntry: the ZipEntry from which to obtain values.

Public methods

clone

Added in API level 1
Object clone ()

Returns a deep copy of this zip entry.

Returns
Object a copy of this object.

getComment

Added in API level 1
String getComment ()

Returns the comment for this ZipEntry, or null if there is no comment. If we're reading a zip file using ZipInputStream, the comment is not available.

Returns
String

getCompressedSize

Added in API level 1
long getCompressedSize ()

Gets the compressed size of this ZipEntry.

Returns
long the compressed size, or -1 if the compressed size has not been set.

getCrc

Added in API level 1
long getCrc ()

Gets the checksum for this ZipEntry.

Returns
long the checksum, or -1 if the checksum has not been set.

getExtra

Added in API level 1
byte[] getExtra ()

Gets the extra information for this ZipEntry.

Returns
byte[] a byte array containing the extra information, or null if there is none.

getMethod

Added in API level 1
int getMethod ()

Gets the compression method for this ZipEntry.

Returns
int the compression method, either DEFLATED, STORED or -1 if the compression method has not been set.

getName

Added in API level 1
String getName ()

Gets the name of this ZipEntry.

Security note: Entry names can represent relative paths. foo/../bar or ../bar/baz, for example. If the entry name is being used to construct a filename or as a path component, it must be validated or sanitized to ensure that files are not written outside of the intended destination directory.

Returns
String the entry name.

getSize

Added in API level 1
long getSize ()

Gets the uncompressed size of this ZipEntry.

Returns
long the uncompressed size, or -1 if the size has not been set.

getTime

Added in API level 1
long getTime ()

Gets the last modification time of this ZipEntry.

Returns
long the last modification time as the number of milliseconds since Jan. 1, 1970.

hashCode

Added in API level 1
int hashCode ()

Returns the hash code for this ZipEntry.

Returns
int the hash code of the entry.

isDirectory

Added in API level 1
boolean isDirectory ()

Determine whether or not this ZipEntry is a directory.

Returns
boolean true when this ZipEntry is a directory, false otherwise.

setComment

Added in API level 1
void setComment (String comment)

Sets the comment for this ZipEntry.

Parameters
comment String
Throws
IllegalArgumentException if the comment is >= 64 Ki UTF-8 bytes.

setCompressedSize

Added in API level 1
void setCompressedSize (long value)

Sets the compressed size for this ZipEntry.

Parameters
value long: the compressed size (in bytes).

setCrc

Added in API level 1
void setCrc (long value)

Sets the checksum for this ZipEntry.

Parameters
value long: the checksum for this entry.
Throws
IllegalArgumentException if value is < 0 or > 0xFFFFFFFFL.

setExtra

Added in API level 1
void setExtra (byte[] data)

Sets the extra information for this ZipEntry.

Parameters
data byte
Throws
IllegalArgumentException if the data length >= 64 KiB.

setMethod

Added in API level 1
void setMethod (int value)

Sets the compression method for this entry to either DEFLATED or STORED. The default is DEFLATED, which will cause the size, compressed size, and CRC to be set automatically, and the entry's data to be compressed. If you switch to STORED note that you'll have to set the size (or compressed size; they must be the same, but it's okay to only set one) and CRC yourself because they must appear before the user data in the resulting zip file. See setSize(long) and setCrc(long).

Parameters
value int
Throws
IllegalArgumentException when value is not DEFLATED or STORED.

setSize

Added in API level 1
void setSize (long value)

Sets the uncompressed size of this ZipEntry.

Parameters
value long: the uncompressed size for this entry.
Throws
IllegalArgumentException if value < 0.

setTime

Added in API level 1
void setTime (long value)

Sets the modification time of this ZipEntry.

Parameters
value long: the modification time as the number of milliseconds since Jan. 1, 1970.

toString

Added in API level 1
String toString ()

Returns the string representation of this ZipEntry.

Returns
String the string representation of this ZipEntry.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.