net.i2p.i2ptunnel

## Class HTTPResponseOutputStream

- java.lang.Object
- - java.io.OutputStream
  - - java.io.FilterOutputStream
    - - net.i2p.i2ptunnel.HTTPResponseOutputStream

- All Implemented Interfaces:
    Closeable, Flushable

       class HTTPResponseOutputStream
      extends FilterOutputStream

  This does the transparent gzip decompression on the client side. Extended in I2PTunnelHTTPServer to do the compression on the server side. Simple stream for delivering an HTTP response to the client, trivially filtered to make sure "Connection: close" is always in the response. Perhaps add transparent handling of the Content-encoding: x-i2p-gzip, adjusting the headers to say Content-encoding: identity? Content-encoding: gzip is trivial as well, but Transfer-encoding: chunked makes it more work than is worthwhile at the moment.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `_gzip`
    `protected ByteArray` | `_headerBuffer`

    - ### Fields inherited from class java.io.FilterOutputStream

      `out`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HTTPResponseOutputStream(OutputStream raw)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `beginProcessing()`
    `void` | `close()`
    `protected static String` | `filterResponseLine(String line)` Tweak that first HTTP response line (HTTP 200 OK, etc)
    `protected void` | `finishHeaders()`
    `protected boolean` | `shouldCompress()`
    `String` | `toString()`
    `void` | `write(byte[] buf)`
    `void` | `write(byte[] buf, int off, int len)`
    `void` | `write(int c)`

    - ### Methods inherited from class java.io.FilterOutputStream

      `flush`

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

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

- - ### Field Detail

    - #### _headerBuffer

          protected ByteArray _headerBuffer

    - #### _gzip

          protected boolean _gzip

  - ### Constructor Detail

    - #### HTTPResponseOutputStream

          public HTTPResponseOutputStream(OutputStream raw)

  - ### Method Detail

    - #### write

          public void write(int c)
                     throws IOException

      Overrides:
        `write` in class `FilterOutputStream`
      Throws:
        `IOException`

    - #### write

          public void write(byte[] buf)
                     throws IOException

      Overrides:
        `write` in class `FilterOutputStream`
      Throws:
        `IOException`

    - #### write

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

      Overrides:
        `write` in class `FilterOutputStream`
      Throws:
        `IOException`

    - #### filterResponseLine

          protected static String filterResponseLine(String line)

      Tweak that first HTTP response line (HTTP 200 OK, etc)

    - #### shouldCompress

          protected boolean shouldCompress()

    - #### finishHeaders

          protected void finishHeaders()
                                throws IOException

      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Overrides:
        `close` in class `FilterOutputStream`
      Throws:
        `IOException`

    - #### beginProcessing

          protected void beginProcessing()
                                  throws IOException

      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`