Package okio

Class DeflaterSink

  • All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable, Sink

    public final class DeflaterSink
    extends Object
    implements Sink
    A sink that uses DEFLATE to compress data written to another source.

    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 Detail

      • DeflaterSink

        public DeflaterSink​(Sink sink,
                            Deflater deflater)
    • Method Detail

      • write

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

        public void flush()
                   throws IOException
        Description copied from interface: Sink
        Pushes all buffered bytes to their final destination.
        Specified by:
        flush in interface Flushable
        Specified by:
        flush in interface Sink
        Throws:
        IOException - if there are any issues writing the data.
      • close

        public void close()
                   throws 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 AutoCloseable
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface Sink
        Throws:
        IOException
      • timeout

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

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:
           getClass().getName() + '@' + Integer.toHexString(hashCode())

        See Writing a useful toString method if you intend implementing your own toString method.

        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.