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 int CENATT  
    static int CENATX  
    static int CENCOM  
    static int CENCRC  
    static int CENDSK  
    static int CENEXT  
    static int CENFLG  
    static int CENHDR  
    static int CENHOW  
    static int CENLEN  
    static int CENNAM  
    static int CENOFF  
    static long CENSIG  
    static int CENSIZ  
    static int CENTIM  
    static int CENVEM  
    static int CENVER  
    static int DEFLATED
    Zip entry state: Deflated.
    static int ENDCOM  
    static int ENDHDR  
    static int ENDOFF  
    static long ENDSIG  
    static int ENDSIZ  
    static int ENDSUB  
    static int ENDTOT  
    static int EXTCRC  
    static int EXTHDR  
    static int EXTLEN  
    static long EXTSIG  
    static int EXTSIZ  
    static int LOCCRC  
    static int LOCEXT  
    static int LOCFLG  
    static int LOCHDR  
    static int LOCHOW  
    static int LOCLEN  
    static int LOCNAM  
    static long LOCSIG  
    static int LOCSIZ  
    static int LOCTIM  
    static int LOCVER  
    static int STORED
    Zip entry state: Stored.
  • Constructor Summary

    Constructors
    Constructor Description
    ZipEntry​(String name)
    Constructs a new ZipEntry with the specified name.
    ZipEntry​(ZipEntry ze)
    Constructs a new ZipEntry using the values obtained from ze.
  • Method Summary

    Modifier and Type Method Description
    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.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • ZipEntry

      public ZipEntry​(String name)
      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).
    • ZipEntry

      public ZipEntry​(ZipEntry ze)
      Constructs a new ZipEntry using the values obtained from ze.
      Parameters:
      ze - the ZipEntry from which to obtain values.
  • Method Details

    • getComment

      public 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.
    • getCompressedSize

      public long getCompressedSize()
      Gets the compressed size of this ZipEntry.
      Returns:
      the compressed size, or -1 if the compressed size has not been set.
    • getCrc

      public long getCrc()
      Gets the checksum for this ZipEntry.
      Returns:
      the checksum, or -1 if the checksum has not been set.
    • getExtra

      public byte[] getExtra()
      Gets the extra information for this ZipEntry.
      Returns:
      a byte array containing the extra information, or null if there is none.
    • getMethod

      public int getMethod()
      Gets the compression method for this ZipEntry.
      Returns:
      the compression method, either DEFLATED, STORED or -1 if the compression method has not been set.
    • getName

      public String getName()
      Gets the name of this ZipEntry.
      Returns:
      the entry name.
    • getSize

      public long getSize()
      Gets the uncompressed size of this ZipEntry.
      Returns:
      the uncompressed size, or -1 if the size has not been set.
    • getTime

      public long getTime()
      Gets the last modification time of this ZipEntry.
      Returns:
      the last modification time as the number of milliseconds since Jan. 1, 1970.
    • isDirectory

      public boolean isDirectory()
      Determine whether or not this ZipEntry is a directory.
      Returns:
      true when this ZipEntry is a directory, false otherwise.
    • setComment

      public void setComment​(String comment)
      Sets the comment for this ZipEntry.
      Throws:
      IllegalArgumentException - if the comment is >= 64 Ki UTF-8 bytes.
    • setCompressedSize

      public void setCompressedSize​(long value)
      Sets the compressed size for this ZipEntry.
      Parameters:
      value - the compressed size (in bytes).
    • setCrc

      public void setCrc​(long value)
      Sets the checksum for this ZipEntry.
      Parameters:
      value - the checksum for this entry.
      Throws:
      IllegalArgumentException - if value is < 0 or > 0xFFFFFFFFL.
    • setExtra

      public void setExtra​(byte[] data)
      Sets the extra information for this ZipEntry.
      Throws:
      IllegalArgumentException - if the data length >= 64 KiB.
    • setMethod

      public 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).
      Throws:
      IllegalArgumentException - when value is not DEFLATED or STORED.
    • setSize

      public void setSize​(long value)
      Sets the uncompressed size of this ZipEntry.
      Parameters:
      value - the uncompressed size for this entry.
      Throws:
      IllegalArgumentException - if value < 0 or value > 0xFFFFFFFFL.
    • setTime

      public void setTime​(long value)
      Sets the modification time of this ZipEntry.
      Parameters:
      value - the modification time as the number of milliseconds since Jan. 1, 1970.
    • toString

      public String toString()
      Returns the string representation of this ZipEntry.
      Overrides:
      toString in class Object
      Returns:
      the string representation of this ZipEntry.
    • clone

      public Object clone()
      Returns a deep copy of this zip entry.
      Overrides:
      clone in class Object
      Returns:
      a copy of this object.
    • hashCode

      public int hashCode()
      Returns the hash code for this ZipEntry.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of the entry.
      See Also:
      Object.equals(java.lang.Object)