Package okio

Class GzipSink

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

    public final class GzipSink
    extends java.lang.Object
    implements Sink
    A sink that uses GZIP to compress written data to another sink.

    Sync flush

    Aggressive flushing of this stream may result in reduced compression. Each call to flush() immediately compresses all currently-buffered data; this early compression may be less effective than compression performed without flushing.

    This is equivalent to using Deflater with the sync flush option. This class does not offer any partial flush mechanism. For best performance, only call flush() when application behavior requires it.

    • Constructor Summary

      Constructors 
      Constructor Description
      GzipSink​(Sink sink)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Pushes all buffered bytes to their final destination and releases the resources held by this sink.
      java.util.zip.Deflater deflater()
      Returns the Deflater.
      void flush()
      Pushes all buffered bytes to their final destination.
      Timeout timeout()
      Returns the timeout for this sink.
      void write​(Buffer source, long byteCount)
      Removes byteCount bytes from source and appends them to this.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GzipSink

        public GzipSink​(Sink sink)
    • Method Detail

      • write

        public void write​(Buffer source,
                          long byteCount)
                   throws java.io.IOException
        Description copied from interface: Sink
        Removes byteCount bytes from source and appends them to this.
        Specified by:
        write in interface Sink
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: Sink
        Pushes all buffered bytes to their final destination.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in interface Sink
        Throws:
        java.io.IOException
      • timeout

        public Timeout timeout()
        Description copied from interface: Sink
        Returns the timeout for this sink.
        Specified by:
        timeout in interface Sink
      • close

        public void close()
                   throws java.io.IOException
        Description copied from interface: Sink
        Pushes all buffered bytes to their final destination and releases the resources held by this sink. It is an error to write a closed sink. It is safe to close a sink more than once.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface Sink
        Throws:
        java.io.IOException
      • deflater

        public final java.util.zip.Deflater deflater()
        Returns the Deflater. Use it to access stats, dictionary, compression level, etc.