Android APIs
public class

ZipEntry

extends Object
implements Cloneable
java.lang.Object
   ↳ java.util.zip.ZipEntry
Known Direct Subclasses

Class Overview

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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int CENATT

Added in API level 21

Constant Value: 36 (0x00000024)

public static final int CENATX

Added in API level 21

Constant Value: 38 (0x00000026)

public static final int CENCOM

Added in API level 21

Constant Value: 32 (0x00000020)

public static final int CENCRC

Added in API level 21

Constant Value: 16 (0x00000010)

public static final int CENDSK

Added in API level 21

Constant Value: 34 (0x00000022)

public static final int CENEXT

Added in API level 21

Constant Value: 30 (0x0000001e)

public static final int CENFLG

Added in API level 21

Constant Value: 8 (0x00000008)

public static final int CENHDR

Added in API level 21

Constant Value: 46 (0x0000002e)

public static final int CENHOW

Added in API level 21

Constant Value: 10 (0x0000000a)

public static final int CENLEN

Added in API level 21

Constant Value: 24 (0x00000018)

public static final int CENNAM

Added in API level 21

Constant Value: 28 (0x0000001c)

public static final int CENOFF

Added in API level 21

Constant Value: 42 (0x0000002a)

public static final long CENSIG

Added in API level 21

Constant Value: 33639248 (0x0000000002014b50)

public static final int CENSIZ

Added in API level 21

Constant Value: 20 (0x00000014)

public static final int CENTIM

Added in API level 21

Constant Value: 12 (0x0000000c)

public static final int CENVEM

Added in API level 21

Constant Value: 4 (0x00000004)

public static final int CENVER

Added in API level 21

Constant Value: 6 (0x00000006)

public static final int DEFLATED

Added in API level 1

Zip entry state: Deflated.

Constant Value: 8 (0x00000008)

public static final int ENDCOM

Added in API level 21

Constant Value: 20 (0x00000014)

public static final int ENDHDR

Added in API level 21

Constant Value: 22 (0x00000016)

public static final int ENDOFF

Added in API level 21

Constant Value: 16 (0x00000010)

public static final long ENDSIG

Added in API level 21

Constant Value: 101010256 (0x0000000006054b50)

public static final int ENDSIZ

Added in API level 21

Constant Value: 12 (0x0000000c)

public static final int ENDSUB

Added in API level 21

Constant Value: 8 (0x00000008)

public static final int ENDTOT

Added in API level 21

Constant Value: 10 (0x0000000a)

public static final int EXTCRC

Added in API level 21

Constant Value: 4 (0x00000004)

public static final int EXTHDR

Added in API level 21

Constant Value: 16 (0x00000010)

public static final int EXTLEN

Added in API level 21

Constant Value: 12 (0x0000000c)

public static final long EXTSIG

Added in API level 21

Constant Value: 134695760 (0x0000000008074b50)

public static final int EXTSIZ

Added in API level 21

Constant Value: 8 (0x00000008)

public static final int LOCCRC

Added in API level 21

Constant Value: 14 (0x0000000e)

public static final int LOCEXT

Added in API level 21

Constant Value: 28 (0x0000001c)

public static final int LOCFLG

Added in API level 21

Constant Value: 6 (0x00000006)

public static final int LOCHDR

Added in API level 21

Constant Value: 30 (0x0000001e)

public static final int LOCHOW

Added in API level 21

Constant Value: 8 (0x00000008)

public static final int LOCLEN

Added in API level 21

Constant Value: 22 (0x00000016)

public static final int LOCNAM

Added in API level 21

Constant Value: 26 (0x0000001a)

public static final long LOCSIG

Added in API level 21

Constant Value: 67324752 (0x0000000004034b50)

public static final int LOCSIZ

Added in API level 21

Constant Value: 18 (0x00000012)

public static final int LOCTIM

Added in API level 21

Constant Value: 10 (0x0000000a)

public static final int LOCVER

Added in API level 21

Constant Value: 4 (0x00000004)

public static final int STORED

Added in API level 1

Zip entry state: Stored.

Constant Value: 0 (0x00000000)

Public Constructors

public ZipEntry (String name)

Added in API level 1

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

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

public ZipEntry (ZipEntry ze)

Added in API level 1

Constructs a new ZipEntry using the values obtained from ze.

Parameters
ze the ZipEntry from which to obtain values.

Public Methods

public Object clone ()

Added in API level 1

Returns a deep copy of this zip entry.

Returns
  • a copy of this object.

public String getComment ()

Added in API level 1

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.

public long getCompressedSize ()

Added in API level 1

Gets the compressed size of this ZipEntry.

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

public long getCrc ()

Added in API level 1

Gets the checksum for this ZipEntry.

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

public byte[] getExtra ()

Added in API level 1

Gets the extra information for this ZipEntry.

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

public int getMethod ()

Added in API level 1

Gets the compression method for this ZipEntry.

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

public String getName ()

Added in API level 1

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
  • the entry name.

public long getSize ()

Added in API level 1

Gets the uncompressed size of this ZipEntry.

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

public long getTime ()

Added in API level 1

Gets the last modification time of this ZipEntry.

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

public int hashCode ()

Added in API level 1

Returns the hash code for this ZipEntry.

Returns
  • the hash code of the entry.

public boolean isDirectory ()

Added in API level 1

Determine whether or not this ZipEntry is a directory.

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

public void setComment (String comment)

Added in API level 1

Sets the comment for this ZipEntry.

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

public void setCompressedSize (long value)

Added in API level 1

Sets the compressed size for this ZipEntry.

Parameters
value the compressed size (in bytes).

public void setCrc (long value)

Added in API level 1

Sets the checksum for this ZipEntry.

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

public void setExtra (byte[] data)

Added in API level 1

Sets the extra information for this ZipEntry.

Throws
IllegalArgumentException if the data length >= 64 KiB.

public void setMethod (int value)

Added in API level 1

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).

Throws
IllegalArgumentException when value is not DEFLATED or STORED.

public void setSize (long value)

Added in API level 1

Sets the uncompressed size of this ZipEntry.

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

public void setTime (long value)

Added in API level 1

Sets the modification time of this ZipEntry.

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

public String toString ()

Added in API level 1

Returns the string representation of this ZipEntry.

Returns
  • the string representation of this ZipEntry.