GzipOutputFilter (Apache Tomcat 10.1.57 API Documentation)
Description: declaration: package: org.apache.coyote.http11.filters, class: GzipOutputFilter

# Class GzipOutputFilter

java.lang.Object
org.apache.coyote.http11.filters.GzipOutputFilter

All Implemented Interfaces:
  `HttpOutputBuffer, OutputFilter, OutputBuffer`

public class GzipOutputFilter extends Object implements OutputFilter
Gzip output filter that compresses response data using the GZIP algorithm.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `GzipOutputFilter.FakeOutputStream`
  Internal output stream that writes data to the underlying buffer.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected HttpOutputBuffer`
  `buffer`
  Next buffer in the pipeline.
  `protected GZIPOutputStream`
  `compressionStream`
  Compression output stream.
  `protected final OutputStream`
  `fakeOutputStream`
  Fake internal output stream.
  `protected static final Log`
  `log`
  Logger for this filter.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GzipOutputFilter()`
  Constructs a new GzipOutputFilter.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `doWrite(ByteBuffer chunk)`
  Write the given data to the response.
  `void`
  `end()`
  Finish writing the current response.
  `void`
  `flush()`
  Flushes any unwritten data to the client.
  `long`
  `getBytesWritten()`
  Bytes written to the underlying socket.
  `void`
  `recycle()`
  Make the filter ready to process the next request.
  `void`
  `setBuffer(HttpOutputBuffer buffer)`
  Set the next buffer in the filter pipeline.
  `void`
  `setResponse(Response response)`
  Some filters need additional parameters from the response.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### log

    protected static final Log log
    Logger for this filter.

  - ### buffer

    protected HttpOutputBuffer buffer
    Next buffer in the pipeline.

  - ### compressionStream

    protected GZIPOutputStream compressionStream
    Compression output stream.

  - ### fakeOutputStream

    protected final OutputStream fakeOutputStream
    Fake internal output stream.

- ## Constructor Details

  - ### GzipOutputFilter

    public GzipOutputFilter()
    Constructs a new GzipOutputFilter.

- ## Method Details

  - ### doWrite

    public int doWrite(ByteBuffer chunk) throws IOException
    Description copied from interface: `OutputBuffer`
    Write the given data to the response. The caller owns the chunks.
    Specified by:
      `doWrite` in interface `OutputBuffer`
    Parameters:
      `chunk` - data to write
    Returns:
      The number of bytes written which may be less than available in the input chunk
    Throws:
      `IOException` - an underlying I/O error occurred

  - ### getBytesWritten

    public long getBytesWritten()
    Description copied from interface: `OutputBuffer`
    Bytes written to the underlying socket. This includes the effects of chunking, compression, etc.
    Specified by:
      `getBytesWritten` in interface `OutputBuffer`
    Returns:
      Bytes written for the current request

  - ### flush

    public void flush() throws IOException
    Flushes any unwritten data to the client. Added to allow flushing to happen for the gzip'ed outputstream.
    Specified by:
      `flush` in interface `HttpOutputBuffer`
    Throws:
      `IOException` - If an I/O error occurs while flushing

  - ### setResponse

    public void setResponse(Response response)
    Description copied from interface: `OutputFilter`
    Some filters need additional parameters from the response. All the necessary reading can occur in that method, as this method is called after the response header processing is complete.
    Specified by:
      `setResponse` in interface `OutputFilter`
    Parameters:
      `response` - The response to associate with this OutputFilter

  - ### setBuffer

    public void setBuffer(HttpOutputBuffer buffer)
    Description copied from interface: `OutputFilter`
    Set the next buffer in the filter pipeline.
    Specified by:
      `setBuffer` in interface `OutputFilter`
    Parameters:
      `buffer` - The next buffer instance

  - ### end

    public void end() throws IOException
    Description copied from interface: `HttpOutputBuffer`
    Finish writing the current response. It is acceptable to write extra bytes using `OutputBuffer.doWrite(java.nio.ByteBuffer)` during the execution of this method.
    Specified by:
      `end` in interface `HttpOutputBuffer`
    Throws:
      `IOException` - If an I/O error occurs while writing to the client

  - ### recycle

    public void recycle()
    Description copied from interface: `OutputFilter`
    Make the filter ready to process the next request.
    Specified by:
      `recycle` in interface `OutputFilter`