Package java.util.zip

Class ZipEntry

    • 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 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 Detail

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

        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.
      • 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.
      • 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.
      • setDataOffset

        public void setDataOffset​(long value)
      • getDataOffset

        public long getDataOffset()
      • 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.