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 int` | `_bufferSize`
    `protected boolean` | `_closed`
    `protected DeflaterOutputStream` | `_compressedOutputStream`
    `protected long` | `_contentLength`
    `protected boolean` | `_doNotCompress`
    `protected int` | `_minCompressSize`
    `protected OutputStream` | `_out`
    `protected javax.servlet.http.HttpServletRequest` | `_request`
    `protected javax.servlet.http.HttpServletResponse` | `_response`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractCompressedStream(String encoding, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, long contentLength, int bufferSize, int minCompressSize)` Instantiates a new compressed stream.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `protected abstract DeflaterOutputStream` | `createStream()` Create the stream fitting to the underlying compression type.
    `void` | `doCompress()` Do compress.
    `void` | `doNotCompress()` 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` | `setContentLength(long length)` Sets the content length.
    `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

    - #### _request

          protected javax.servlet.http.HttpServletRequest _request

    - #### _response

          protected javax.servlet.http.HttpServletResponse _response

    - #### _out

          protected OutputStream _out

    - #### _bOut

          protected ByteArrayOutputStream2 _bOut

    - #### _compressedOutputStream

          protected DeflaterOutputStream _compressedOutputStream

    - #### _closed

          protected boolean _closed

    - #### _bufferSize

          protected int _bufferSize

    - #### _minCompressSize

          protected int _minCompressSize

    - #### _contentLength

          protected long _contentLength

    - #### _doNotCompress

          protected boolean _doNotCompress

  - ### Constructor Detail

    - #### AbstractCompressedStream

          public AbstractCompressedStream(String encoding,
                                  javax.servlet.http.HttpServletRequest request,
                                  javax.servlet.http.HttpServletResponse response,
                                  long contentLength,
                                  int bufferSize,
                                  int minCompressSize)
                                   throws IOException

      Instantiates a new compressed stream.
      Parameters:
        `request` - the request
        `response` - the response
        `contentLength` - the content length
        `bufferSize` - the buffer size
        `minCompressSize` - the min compress size
      Throws:
        `IOException` - Signals that an I/O exception has occurred.

  - ### Method Detail

    - #### resetBuffer

          public void resetBuffer()

      Reset buffer.

    - #### setContentLength

          public void setContentLength(long length)

      Sets the content length.
      Parameters:
        `length` - the new content length

    - #### 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()
                             throws IOException

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

    - #### getOutputStream

          public OutputStream getOutputStream()

      See Also:
        `CompressedStream`

    - #### isClosed

          public boolean isClosed()

      See Also:
        `CompressedStream`

    - #### newWriter

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

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

    - #### 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-2012 Mort Bay Consulting. All Rights Reserved.