Class ZipArchiveInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable
    Direct Known Subclasses:
    JarArchiveInputStream


    public class ZipArchiveInputStream
    extends ArchiveInputStream
    Implements an input stream that can read Zip archives.

    Note that ZipArchiveEntry.getSize() may return -1 if the DEFLATE algorithm is used, as the size information is not available from the header.

    The ZipFile class is preferred when reading from files.

    As of Apache Commons Compress it transparently supports Zip64 extensions and thus individual entries and archives larger than 4 GB or with more than 65536 entries.

    See Also:
    ZipFile
    • Constructor Detail

      • ZipArchiveInputStream

        public ZipArchiveInputStream(InputStream inputStream)
      • ZipArchiveInputStream

        public ZipArchiveInputStream(InputStream inputStream,
                                     String encoding)
        Parameters:
        encoding - the encoding to use for file names, use null for the platform's default encoding
        Since:
        1.5
      • ZipArchiveInputStream

        public ZipArchiveInputStream(InputStream inputStream,
                                     String encoding,
                                     boolean useUnicodeExtraFields)
        Parameters:
        encoding - the encoding to use for file names, use null for the platform's default encoding
        useUnicodeExtraFields - whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.
      • ZipArchiveInputStream

        public ZipArchiveInputStream(InputStream inputStream,
                                     String encoding,
                                     boolean useUnicodeExtraFields,
                                     boolean allowStoredEntriesWithDataDescriptor)
        Parameters:
        encoding - the encoding to use for file names, use null for the platform's default encoding
        useUnicodeExtraFields - whether to use InfoZIP Unicode Extra Fields (if present) to set the file names.
        allowStoredEntriesWithDataDescriptor - whether the stream will try to read STORED entries that use a data descriptor
        Since:
        1.1
    • Method Detail

      • canReadEntryData

        public boolean canReadEntryData(ArchiveEntry ae)
        Whether this class is able to read the given entry.

        May return false if it is set up to use encryption or a compression method that hasn't been implemented yet.

        Overrides:
        canReadEntryData in class  ArchiveInputStream
        Parameters:
        ae - the entry to test
        Returns:
        This implementation always returns true.
        Since:
        1.1
      • skip

        public long skip(long value)
                  throws IOException
        Skips over and discards value bytes of data from this input stream.

        This implementation may end up skipping over some smaller number of bytes, possibly 0, if and only if it reaches the end of the underlying stream.

        The actual number of bytes skipped is returned.

        Overrides:
        skip in class  InputStream
        Parameters:
        value - the number of bytes to be skipped.
        Returns:
        the actual number of bytes skipped.
        Throws:
        IOException - - if an I/O error occurs.
        IllegalArgumentException - - if value is negative.
      • matches

        public static boolean matches(byte[] signature,
                                      int length)
        Checks if the signature matches what is expected for a zip file. Does not currently handle self-extracting zips which may have arbitrary leading content.
        Parameters:
        signature - the bytes to check
        length - the number of bytes to check
        Returns:
        true, if this stream is a zip archive stream, false otherwise