Class ZipStream

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

    public class ZipStream
    extends CompressedStream
    This class implements a stream filter for reading and writing files in the ZIP file format. Currently supports only compressed entries.

    See the sammple TotalCross3/src/tc/samples/util/zip/zip.
    Since:
    TotalCross 1.20
    • Field Detail

      • STORED

        public static final int STORED
        Compression method for uncompressed (STORED) entries.
        See Also:
        Constant Field Values
      • DEFLATED

        public static final int DEFLATED
        Compression method for compressed (DEFLATED) entries.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ZipStream

        public ZipStream​(RandomAccessStream stream,
                         int mode)
        Creates a new ZIP stream that may be used to read compressed data from the given stream, or to write compressed data to the given stream.
        Parameters:
        stream - input stream.
        mode - its value must be either DEFLATE or INFLATE.
        Since:
        TotalCross 1.20
    • Method Detail

      • available

        public int available()
                      throws IOException
        Returns 0 after EOF has reached for the current entry data, otherwise always return 1.
        Programs should not count on this method to return the actual number of bytes that could be read without blocking.
        Returns:
        1 before EOF and 0 after EOF has reached for current entry.
        Throws:
        IOException - if an I/O error occurs.
        Since:
        TotalCross 1.20
      • getNextEntry

        public ZipEntry getNextEntry()
                              throws IOException
        Reads the next ZIP file entry and positions the stream at the beginning of the entry data.
        Returns:
        the next ZIP file entry, or null if there are no more entries
        Throws:
        IOException - if an I/O error has occurred
        Since:
        TotalCross 1.20
      • putNextEntry

        public void putNextEntry​(ZipEntry entry)
                          throws IOException,
                                 ZipException
        Begins writing a new ZIP file entry and positions the stream to the start of the entry data. Closes the current entry if still active.
        Parameters:
        entry - the ZIP entry to be written
        Throws:
        IOException - if an I/O error has occurred
        ZipException
        Since:
        TotalCross 1.20
      • closeEntry

        public void closeEntry()
                        throws IOException,
                               ZipException
        Closes the current ZIP entry and positions the stream for reading (INFLATE) or writing (DEFLATE) the next entry.
        Throws:
        IOException - if an I/O error has occurred
        ZipException
        Since:
        TotalCross 1.20
      • close

        public void close()
                   throws IOException
        Description copied from class: CompressedStream
        Closes this stream WITHOUT closing the underlying stream, which must be explicitly closed by the user.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class CompressedStream
        Throws:
        IOException - If an I/O error occurs.