org.eclipse.jetty.http.gzip

## Class AbstractCompressedStream

- java.lang.Object
- - java.io.OutputStream
  - - javax.servlet.ServletOutputStream
    - - org.eclipse.jetty.http.gzip.AbstractCompressedStream

- All Implemented Interfaces:
    Closeable, Flushable, AutoCloseable

      public abstract class AbstractCompressedStream
      extends javax.servlet.ServletOutputStream

  Skeletal implementation of a CompressedStream. This class adds compression features to a ServletOutputStream and takes care of setting response headers, etc. Major work and configuration is done here. Subclasses using different kinds of compression only have to implement the abstract methods doCompress() and setContentEncoding() using the desired compression and setting the appropriate Content-Encoding header string.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ByteArrayOutputStream2` | `_bOut`
    `protected boolean` | `_closed`
    `protected DeflaterOutputStream` | `_compressedOutputStream`
    `protected boolean` | `_doNotCompress`
    `protected OutputStream` | `_out`
    `protected javax.servlet.http.HttpServletResponse` | `_response`
    `protected String` | `_vary`
    `protected CompressedResponseWrapper` | `_wrapper`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractCompressedStream(String encoding, javax.servlet.http.HttpServletRequest request, CompressedResponseWrapper wrapper, String vary)` Instantiates a new compressed stream.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addHeader(String name, String value)`
    `void` | `close()`
    `protected abstract DeflaterOutputStream` | `createStream()` Create the stream fitting to the underlying compression type.
    `void` | `doCompress()` Do compress.
    `void` | `doNotCompress(boolean sendVary)` Do not compress.
    `void` | `finish()` Finish.
    `void` | `flush()`
    `OutputStream` | `getOutputStream()`
    `boolean` | `isClosed()`
    `protected PrintWriter` | `newWriter(OutputStream out, String encoding)` Allows derived implementations to replace PrintWriter implementation.
    `void` | `resetBuffer()` Reset buffer.
    `void` | `setBufferSize(int bufferSize)`
    `void` | `setContentLength()`
    `protected void` | `setHeader(String name, String value)`
    `void` | `write(byte[] b)`
    `void` | `write(byte[] b, int off, int len)`
    `void` | `write(int b)`

    - ### Methods inherited from class javax.servlet.ServletOutputStream

      `print, print, print, print, print, print, print, println, println, println, println, println, println, println, println`

    - ### Methods inherited from class java.lang.Object

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

- - ### Field Detail

    - #### _vary

          protected final String _vary

    - #### _wrapper

          protected final CompressedResponseWrapper _wrapper

    - #### _response

          protected final javax.servlet.http.HttpServletResponse _response

    - #### _out

          protected OutputStream _out

    - #### _bOut

          protected ByteArrayOutputStream2 _bOut

    - #### _compressedOutputStream

          protected DeflaterOutputStream _compressedOutputStream

    - #### _closed

          protected boolean _closed

    - #### _doNotCompress

          protected boolean _doNotCompress

  - ### Constructor Detail

    - #### AbstractCompressedStream

          public AbstractCompressedStream(String encoding,
                                  javax.servlet.http.HttpServletRequest request,
                                  CompressedResponseWrapper wrapper,
                                  String vary)
                                   throws IOException

      Instantiates a new compressed stream.
      Throws:
        `IOException`

  - ### Method Detail

    - #### resetBuffer

          public void resetBuffer()

      Reset buffer.

    - #### setBufferSize

          public void setBufferSize(int bufferSize)

    - #### setContentLength

          public void setContentLength()

    - #### flush

          public void flush()
                     throws IOException

      Specified by:
        `flush` in interface `Flushable`
      Overrides:
        `flush` in class `OutputStream`
      Throws:
        `IOException`
      See Also:
        `OutputStream.flush()`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `OutputStream`
      Throws:
        `IOException`
      See Also:
        `OutputStream.close()`

    - #### finish

          public void finish()
                      throws IOException

      Finish.
      Throws:
        `IOException` - Signals that an I/O exception has occurred.

    - #### write

          public void write(int b)
                     throws IOException

      Specified by:
        `write` in class `OutputStream`
      Throws:
        `IOException`
      See Also:
        `OutputStream.write(int)`

    - #### write

          public void write(byte[] b)
                     throws IOException

      Overrides:
        `write` in class `OutputStream`
      Throws:
        `IOException`
      See Also:
        `OutputStream.write(byte[])`

    - #### write

          public void write(byte[] b,
                   int off,
                   int len)
                     throws IOException

      Overrides:
        `write` in class `OutputStream`
      Throws:
        `IOException`
      See Also:
        `OutputStream.write(byte[], int, int)`

    - #### doCompress

          public void doCompress()
                          throws IOException

      Do compress.
      Throws:
        `IOException` - Signals that an I/O exception has occurred.

    - #### doNotCompress

          public void doNotCompress(boolean sendVary)
                             throws IOException

      Do not compress.
      Throws:
        `IOException` - Signals that an I/O exception has occurred.

    - #### getOutputStream

          public OutputStream getOutputStream()

      See Also:
        `org.eclipse.jetty.http.gzip.CompressedStream#getOutputStream()`

    - #### isClosed

          public boolean isClosed()

      See Also:
        `org.eclipse.jetty.http.gzip.CompressedStream#isClosed()`

    - #### newWriter

          protected PrintWriter newWriter(OutputStream out,
                              String encoding)
                                   throws UnsupportedEncodingException

      Allows derived implementations to replace PrintWriter implementation.
      Throws:
        `UnsupportedEncodingException`

    - #### addHeader

          protected void addHeader(String name,
                       String value)

    - #### setHeader

          protected void setHeader(String name,
                       String value)

    - #### createStream

          protected abstract DeflaterOutputStream createStream()
                                                        throws IOException

      Create the stream fitting to the underlying compression type.
      Throws:
        `IOException` - Signals that an I/O exception has occurred.

Copyright © 1995-2016 Mort Bay Consulting. All Rights Reserved.