Class ZipInputStream

All Implemented Interfaces:
Closeable, 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 Details

    • crc

      private CRC32 crc
    • entry

      private ZipEntry entry
    • 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 Details

    • ZipInputStream

      public ZipInputStream(InputStream in)
      Creates a new Zip input stream, reading a zip archive.
  • Method Details

    • fillBuf

      private void fillBuf() throws IOException
      Throws:
      IOException
    • readBuf

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

      private void readFully(byte[] out) throws IOException
      Throws:
      IOException
    • readLeByte

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

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

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

      public ZipEntry getNextEntry() throws 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:
      IOException
    • readDataDescr

      private void readDataDescr() throws IOException
      Throws:
      IOException
    • closeEntry

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

      public int available() throws 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:
      IOException
    • read

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

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

      protected ZipEntry createZipEntry(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.