Class ZipInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ZipConstants

    public class ZipInputStream
    extends InflaterInputStream
    implements ZipConstants
    This is a FilterInputStream that reads the files in an zip archive one after another. It has a special method to get the zip entry of the next file. The zip entry contains information about the file name size, compressed size, CRC, etc. It includes support for STORED and DEFLATED entries.
    • Field Detail

      • csize

        private int csize
      • size

        private int size
      • method

        private int method
      • flags

        private int flags
      • avail

        private int avail
      • entryAtEOF

        private boolean entryAtEOF
    • Constructor Detail

      • ZipInputStream

        public ZipInputStream​(java.io.InputStream in)
        Creates a new Zip input stream, reading a zip archive.
    • Method Detail

      • fillBuf

        private void fillBuf()
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • readBuf

        private int readBuf​(byte[] out,
                            int offset,
                            int length)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readFully

        private void readFully​(byte[] out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • readLeByte

        private final int readLeByte()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • readLeShort

        private final int readLeShort()
                               throws java.io.IOException
        Read an unsigned short in little endian byte order.
        Throws:
        java.io.IOException
      • readLeInt

        private final int readLeInt()
                             throws java.io.IOException
        Read an int in little endian byte order.
        Throws:
        java.io.IOException
      • getNextEntry

        public ZipEntry getNextEntry()
                              throws java.io.IOException
        Open the next entry from the zip archive, and return its description. If the previous entry wasn't closed, this method will close it.
        Throws:
        java.io.IOException
      • readDataDescr

        private void readDataDescr()
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • closeEntry

        public void closeEntry()
                        throws java.io.IOException
        Closes the current zip entry and moves to the next one.
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Description copied from class: InflaterInputStream
        Returns 0 once the end of the stream (EOF) has been reached. Otherwise returns 1.
        Overrides:
        available in class InflaterInputStream
        Throws:
        java.io.IOException
      • read

        public int read()
                 throws java.io.IOException
        Reads a byte from the current zip entry.
        Overrides:
        read in class InflaterInputStream
        Returns:
        the byte or -1 on EOF.
        Throws:
        java.io.IOException - if a i/o error occured.
        ZipException - if the deflated stream is corrupted.
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Reads a block of bytes from the current zip entry.
        Overrides:
        read in class InflaterInputStream
        Parameters:
        b - the array to read and decompress data into
        off - the offset indicating where the data should be placed
        len - the number of bytes to decompress
        Returns:
        the number of bytes read (may be smaller, even before EOF), or -1 on EOF.
        Throws:
        java.io.IOException - if a i/o error occured.
        ZipException - if the deflated stream is corrupted.
      • close

        public void close()
                   throws java.io.IOException
        Closes the zip file.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class InflaterInputStream
        Throws:
        java.io.IOException - if a i/o error occured.
      • createZipEntry

        protected ZipEntry createZipEntry​(java.lang.String name)
        Creates a new zip entry for the given name. This is equivalent to new ZipEntry(name).
        Parameters:
        name - the name of the zip entry.