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 withZipFile.getInputStream(java.util.zip.ZipEntry). The class documentation forZipInputStreamandZipOutputStreamshows howZipEntryis 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
Constructors Constructor Description ZipEntry(String name)Constructs a newZipEntrywith the specified name.ZipEntry(String name, String comment, long crc, long compressedSize, long size, int compressionMethod, int time, int modDate, byte[] extra, long localHeaderRelOffset, long dataOffset)ZipEntry(ZipEntry ze)Constructs a newZipEntryusing the values obtained fromze.
-
Method Summary
All Methods Instance Methods Concrete Methods 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.longgetDataOffset()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.voidsetDataOffset(long value)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 Detail
-
DEFLATED
public static final int DEFLATED
Zip entry state: Deflated.- See Also:
- Constant Field Values
-
STORED
public static final int STORED
Zip entry state: Stored.- See Also:
- Constant Field Values
-
LOCSIG
public static final long LOCSIG
- See Also:
- Constant Field Values
-
EXTSIG
public static final long EXTSIG
- See Also:
- Constant Field Values
-
CENSIG
public static final long CENSIG
- See Also:
- Constant Field Values
-
ENDSIG
public static final long ENDSIG
- See Also:
- Constant Field Values
-
LOCHDR
public static final int LOCHDR
- See Also:
- Constant Field Values
-
EXTHDR
public static final int EXTHDR
- See Also:
- Constant Field Values
-
CENHDR
public static final int CENHDR
- See Also:
- Constant Field Values
-
ENDHDR
public static final int ENDHDR
- See Also:
- Constant Field Values
-
LOCVER
public static final int LOCVER
- See Also:
- Constant Field Values
-
LOCFLG
public static final int LOCFLG
- See Also:
- Constant Field Values
-
LOCHOW
public static final int LOCHOW
- See Also:
- Constant Field Values
-
LOCTIM
public static final int LOCTIM
- See Also:
- Constant Field Values
-
LOCCRC
public static final int LOCCRC
- See Also:
- Constant Field Values
-
LOCSIZ
public static final int LOCSIZ
- See Also:
- Constant Field Values
-
LOCLEN
public static final int LOCLEN
- See Also:
- Constant Field Values
-
LOCNAM
public static final int LOCNAM
- See Also:
- Constant Field Values
-
LOCEXT
public static final int LOCEXT
- See Also:
- Constant Field Values
-
EXTCRC
public static final int EXTCRC
- See Also:
- Constant Field Values
-
EXTSIZ
public static final int EXTSIZ
- See Also:
- Constant Field Values
-
EXTLEN
public static final int EXTLEN
- See Also:
- Constant Field Values
-
CENVEM
public static final int CENVEM
- See Also:
- Constant Field Values
-
CENVER
public static final int CENVER
- See Also:
- Constant Field Values
-
CENFLG
public static final int CENFLG
- See Also:
- Constant Field Values
-
CENHOW
public static final int CENHOW
- See Also:
- Constant Field Values
-
CENTIM
public static final int CENTIM
- See Also:
- Constant Field Values
-
CENCRC
public static final int CENCRC
- See Also:
- Constant Field Values
-
CENSIZ
public static final int CENSIZ
- See Also:
- Constant Field Values
-
CENLEN
public static final int CENLEN
- See Also:
- Constant Field Values
-
CENNAM
public static final int CENNAM
- See Also:
- Constant Field Values
-
CENEXT
public static final int CENEXT
- See Also:
- Constant Field Values
-
CENCOM
public static final int CENCOM
- See Also:
- Constant Field Values
-
CENDSK
public static final int CENDSK
- See Also:
- Constant Field Values
-
CENATT
public static final int CENATT
- See Also:
- Constant Field Values
-
CENATX
public static final int CENATX
- See Also:
- Constant Field Values
-
CENOFF
public static final int CENOFF
- See Also:
- Constant Field Values
-
ENDSUB
public static final int ENDSUB
- See Also:
- Constant Field Values
-
ENDTOT
public static final int ENDTOT
- See Also:
- Constant Field Values
-
ENDSIZ
public static final int ENDSIZ
- See Also:
- Constant Field Values
-
ENDOFF
public static final int ENDOFF
- See Also:
- Constant Field Values
-
ENDCOM
public static final int ENDCOM
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ZipEntry
public ZipEntry(String name, String comment, long crc, long compressedSize, long size, int compressionMethod, int time, int modDate, byte[] extra, long localHeaderRelOffset, long dataOffset)
-
ZipEntry
public ZipEntry(String name)
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
public ZipEntry(ZipEntry ze)
Constructs a newZipEntryusing the values obtained fromze.- Parameters:
ze- theZipEntryfrom which to obtain values.
-
-
Method Detail
-
getComment
public String 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
public String getName()
Gets the name of thisZipEntry.Security note: Entry names can represent relative paths.
foo/../baror../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.
-
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
public void setComment(String comment)
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.
-
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.
-
setDataOffset
public void setDataOffset(long value)
-
getDataOffset
public long getDataOffset()
-
toString
public String toString()
Returns the string representation of thisZipEntry.
-
clone
public Object 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)
-
-