Class CompressedStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    GZipStream, ZipStream, ZLibStream

    public abstract class CompressedStream
    extends Stream
    Base class for stream filters that perform data compression and decompression.
    Since:
    TotalCross 1.12
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object compressedStream  
      static int DEFLATE
      Used to create a stream that will be used for data compression.
      static int INFLATE
      Used to create a stream that will be used for data decompression.
      protected int mode  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CompressedStream()  
      protected CompressedStream​(Stream stream, int mode)
      Creates a CompressedStream object that may be used to read compressed data from the given stream, or to write compressed data to the given stream.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes this stream WITHOUT closing the underlying stream, which must be explicitly closed by the user.
      protected abstract java.lang.Object createDeflate​(Stream stream)  
      protected abstract java.lang.Object createInflate​(Stream stream)  
      protected void finalize()  
      int readBytes​(byte[] buf, int start, int count)
      Attempts to read count bytes to the given byte array, starting from offset start.
      This method can be used only with CompressedStreams created in INFLATE mode, and should be used only for reading compressed data from the original stream, returning uncompressed data on the give byte array.
      int writeBytes​(byte[] buf, int start, int count)
      Attempts to write count bytes from the given byte array, starting from offset start.
      This method can be used only with CompressedStreams created in DEFLATE mode, and should be used only for compressing the contents of the given byte array, and writing the compressed data to the original stream.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • compressedStream

        protected java.lang.Object compressedStream
      • mode

        protected int mode
      • DEFLATE

        public static final int DEFLATE
        Used to create a stream that will be used for data compression. In this mode, you may NOT use the method readBytes.
        See Also:
        Constant Field Values
      • INFLATE

        public static final int INFLATE
        Used to create a stream that will be used for data decompression. In this mode, you may NOT use the method writeBytes.
        See Also:
        Constant Field Values
    • Constructor Detail

      • CompressedStream

        protected CompressedStream()
      • CompressedStream

        protected CompressedStream​(Stream stream,
                                   int mode)
        Creates a CompressedStream object 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.12
    • Method Detail

      • createDeflate

        protected abstract java.lang.Object createDeflate​(Stream stream)
      • createInflate

        protected abstract java.lang.Object createInflate​(Stream stream)
      • readBytes

        public int readBytes​(byte[] buf,
                             int start,
                             int count)
                      throws IOException,
                             ZipException
        Attempts to read count bytes to the given byte array, starting from offset start.
        This method can be used only with CompressedStreams created in INFLATE mode, and should be used only for reading compressed data from the original stream, returning uncompressed data on the give byte array.
        Specified by:
        readBytes in class Stream
        Parameters:
        buf - the byte array to read data into
        start - the start position in the array
        count - the number of bytes to read
        Throws:
        IOException
        ZipException
        Since:
        TotalCross 1.12
      • writeBytes

        public int writeBytes​(byte[] buf,
                              int start,
                              int count)
                       throws IOException
        Attempts to write count bytes from the given byte array, starting from offset start.
        This method can be used only with CompressedStreams created in DEFLATE mode, and should be used only for compressing the contents of the given byte array, and writing the compressed data to the original stream.
        Specified by:
        writeBytes in class Stream
        Parameters:
        buf - the byte array to write data from
        start - the start position in the byte array
        count - the number of bytes to write
        Returns:
        the number of bytes actually written
        Throws:
        IOException
        Since:
        TotalCross 1.12
      • close

        public void close()
                   throws IOException
        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
        Throws:
        IOException - If an I/O error occurs.
        Since:
        TotalCross 1.12
      • finalize

        protected void finalize()
        Overrides:
        finalize in class java.lang.Object