Package java.util.zip
Class ZipEntry
java.lang.Object
java.util.zip.ZipEntry
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
JarEntry
public class ZipEntry extends Object implements Cloneable
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
ZipFile.getInputStream(java.util.zip.ZipEntry). The class documentation for ZipInputStream and
ZipOutputStream shows how ZipEntry is used in conjunction with those two classes.-
Field Summary
Fields Modifier and Type Field Description static intCENATTstatic intCENATXstatic intCENCOMstatic intCENCRCstatic intCENDSKstatic intCENEXTstatic intCENFLGstatic intCENHDRstatic intCENHOWstatic intCENLENstatic intCENNAMstatic intCENOFFstatic longCENSIGstatic intCENSIZstatic intCENTIMstatic intCENVEMstatic intCENVERstatic intDEFLATEDZip entry state: Deflated.static intENDCOMstatic intENDHDRstatic intENDOFFstatic longENDSIGstatic intENDSIZstatic intENDSUBstatic intENDTOTstatic intEXTCRCstatic intEXTHDRstatic intEXTLENstatic longEXTSIGstatic intEXTSIZstatic intLOCCRCstatic intLOCEXTstatic intLOCFLGstatic intLOCHDRstatic intLOCHOWstatic intLOCLENstatic intLOCNAMstatic longLOCSIGstatic intLOCSIZstatic intLOCTIMstatic intLOCVERstatic intSTOREDZip entry state: Stored. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description Objectclone()Returns a deep copy of this zip entry.StringgetComment()Returns the comment for thisZipEntry, ornullif there is no comment.longgetCompressedSize()Gets the compressed size of thisZipEntry.longgetCrc()Gets the checksum for thisZipEntry.byte[]getExtra()Gets the extra information for thisZipEntry.intgetMethod()Gets the compression method for thisZipEntry.StringgetName()Gets the name of thisZipEntry.longgetSize()Gets the uncompressed size of thisZipEntry.longgetTime()Gets the last modification time of thisZipEntry.inthashCode()Returns the hash code for thisZipEntry.booleanisDirectory()Determine whether or not thisZipEntryis a directory.voidsetComment(String comment)Sets the comment for thisZipEntry.voidsetCompressedSize(long value)Sets the compressed size for thisZipEntry.voidsetCrc(long value)Sets the checksum for thisZipEntry.voidsetExtra(byte[] data)Sets the extra information for thisZipEntry.voidsetMethod(int value)Sets the compression method for this entry to eitherDEFLATEDorSTORED.voidsetSize(long value)Sets the uncompressed size of thisZipEntry.voidsetTime(long value)Sets the modification time of thisZipEntry.StringtoString()Returns the string representation of thisZipEntry.
-
Field Details
-
DEFLATED
public static final int DEFLATEDZip entry state: Deflated.- See Also:
- Constant Field Values
-
STORED
public static final int STOREDZip entry state: Stored.- See Also:
- Constant Field Values
-
LOCSIG
static final long LOCSIG- See Also:
- Constant Field Values
-
EXTSIG
static final long EXTSIG- See Also:
- Constant Field Values
-
CENSIG
static final long CENSIG- See Also:
- Constant Field Values
-
ENDSIG
static final long ENDSIG- See Also:
- Constant Field Values
-
LOCHDR
static final int LOCHDR- See Also:
- Constant Field Values
-
EXTHDR
static final int EXTHDR- See Also:
- Constant Field Values
-
CENHDR
static final int CENHDR- See Also:
- Constant Field Values
-
ENDHDR
static final int ENDHDR- See Also:
- Constant Field Values
-
LOCVER
static final int LOCVER- See Also:
- Constant Field Values
-
LOCFLG
static final int LOCFLG- See Also:
- Constant Field Values
-
LOCHOW
static final int LOCHOW- See Also:
- Constant Field Values
-
LOCTIM
static final int LOCTIM- See Also:
- Constant Field Values
-
LOCCRC
static final int LOCCRC- See Also:
- Constant Field Values
-
LOCSIZ
static final int LOCSIZ- See Also:
- Constant Field Values
-
LOCLEN
static final int LOCLEN- See Also:
- Constant Field Values
-
LOCNAM
static final int LOCNAM- See Also:
- Constant Field Values
-
LOCEXT
static final int LOCEXT- See Also:
- Constant Field Values
-
EXTCRC
static final int EXTCRC- See Also:
- Constant Field Values
-
EXTSIZ
static final int EXTSIZ- See Also:
- Constant Field Values
-
EXTLEN
static final int EXTLEN- See Also:
- Constant Field Values
-
CENVEM
static final int CENVEM- See Also:
- Constant Field Values
-
CENVER
static final int CENVER- See Also:
- Constant Field Values
-
CENFLG
static final int CENFLG- See Also:
- Constant Field Values
-
CENHOW
static final int CENHOW- See Also:
- Constant Field Values
-
CENTIM
static final int CENTIM- See Also:
- Constant Field Values
-
CENCRC
static final int CENCRC- See Also:
- Constant Field Values
-
CENSIZ
static final int CENSIZ- See Also:
- Constant Field Values
-
CENLEN
static final int CENLEN- See Also:
- Constant Field Values
-
CENNAM
static final int CENNAM- See Also:
- Constant Field Values
-
CENEXT
static final int CENEXT- See Also:
- Constant Field Values
-
CENCOM
static final int CENCOM- See Also:
- Constant Field Values
-
CENDSK
static final int CENDSK- See Also:
- Constant Field Values
-
CENATT
static final int CENATT- See Also:
- Constant Field Values
-
CENATX
static final int CENATX- See Also:
- Constant Field Values
-
CENOFF
static final int CENOFF- See Also:
- Constant Field Values
-
ENDSUB
static final int ENDSUB- See Also:
- Constant Field Values
-
ENDTOT
static final int ENDTOT- See Also:
- Constant Field Values
-
ENDSIZ
static final int ENDSIZ- See Also:
- Constant Field Values
-
ENDOFF
static final int ENDOFF- See Also:
- Constant Field Values
-
ENDCOM
static final int ENDCOM- See Also:
- Constant Field Values
-
-
Constructor Details
-
ZipEntry
Constructs a newZipEntrywith the specified name. The name is actually a path, and may contain/characters.- Throws:
IllegalArgumentException- if the name length is outside the range (> 0xFFFF).
-
ZipEntry
Constructs a newZipEntryusing the values obtained fromze.- Parameters:
ze- theZipEntryfrom which to obtain values.
-
-
Method Details
-
getComment
Returns the comment for thisZipEntry, ornullif there is no comment. If we're reading a zip file usingZipInputStream, the comment is not available. -
getCompressedSize
public long getCompressedSize()Gets the compressed size of thisZipEntry.- Returns:
- the compressed size, or -1 if the compressed size has not been set.
-
getCrc
public long getCrc()Gets the checksum for thisZipEntry.- Returns:
- the checksum, or -1 if the checksum has not been set.
-
getExtra
public byte[] getExtra()Gets the extra information for thisZipEntry.- Returns:
- a byte array containing the extra information, or
nullif there is none.
-
getMethod
public int getMethod()Gets the compression method for thisZipEntry.- Returns:
- the compression method, either
DEFLATED,STOREDor -1 if the compression method has not been set.
-
getName
Gets the name of thisZipEntry.- Returns:
- the entry name.
-
getSize
public long getSize()Gets the uncompressed size of thisZipEntry.- Returns:
- the uncompressed size, or
-1if the size has not been set.
-
getTime
public long getTime()Gets the last modification time of thisZipEntry.- Returns:
- the last modification time as the number of milliseconds since Jan. 1, 1970.
-
isDirectory
public boolean isDirectory()Determine whether or not thisZipEntryis a directory.- Returns:
truewhen thisZipEntryis a directory,falseotherwise.
-
setComment
Sets the comment for thisZipEntry.- Throws:
IllegalArgumentException- if the comment is >= 64 Ki UTF-8 bytes.
-
setCompressedSize
public void setCompressedSize(long value)Sets the compressed size for thisZipEntry.- Parameters:
value- the compressed size (in bytes).
-
setCrc
public void setCrc(long value)Sets the checksum for thisZipEntry.- Parameters:
value- the checksum for this entry.- Throws:
IllegalArgumentException- ifvalueis < 0 or > 0xFFFFFFFFL.
-
setExtra
public void setExtra(byte[] data)Sets the extra information for thisZipEntry.- Throws:
IllegalArgumentException- if the data length >= 64 KiB.
-
setMethod
public void setMethod(int value)Sets the compression method for this entry to eitherDEFLATEDorSTORED. The default isDEFLATED, which will cause the size, compressed size, and CRC to be set automatically, and the entry's data to be compressed. If you switch toSTOREDnote 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. SeesetSize(long)andsetCrc(long).- Throws:
IllegalArgumentException- when value is notDEFLATEDorSTORED.
-
setSize
public void setSize(long value)Sets the uncompressed size of thisZipEntry.- Parameters:
value- the uncompressed size for this entry.- Throws:
IllegalArgumentException- ifvalue< 0 orvalue> 0xFFFFFFFFL.
-
setTime
public void setTime(long value)Sets the modification time of thisZipEntry.- Parameters:
value- the modification time as the number of milliseconds since Jan. 1, 1970.
-
toString
Returns the string representation of thisZipEntry. -
clone
Returns a deep copy of this zip entry. -
hashCode
public int hashCode()Returns the hash code for thisZipEntry.- Overrides:
hashCodein classObject- Returns:
- the hash code of the entry.
- See Also:
Object.equals(java.lang.Object)
-