GZipHandler (RabbIT/4)
Date: 2009-10-13

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## rabbit.handler
Class GZipHandler

    java.lang.Object
      rabbit.handler.BaseHandler
          rabbit.handler.GZipHandler

All Implemented Interfaces:
  Handler, HandlerFactory, AsyncListener, BlockListener, BlockSentListener, HttpHeaderSentListener

Direct Known Subclasses:
  FilterHandler

    public class GZipHandler

extends BaseHandler

This handler compresses the data passing through it.

Author:
  Robert Olofsson

Field Summary
`protected boolean` | `compress`

Fields inherited from class rabbit.handler.BaseHandler
`cacheChannel, clientHandle, con, content, entry, mayCache, mayFilter, request, response, size, tlh, totalRead`

Constructor Summary
`GZipHandler()` For creating the factory.
`GZipHandler(Connection con, TrafficLoggerHandler tlh, HttpHeader request, BufferHandle clientHandle, HttpHeader response, ResourceSource content, boolean mayCache, boolean mayFilter, long size, boolean compress)` Create a new GZipHandler for the given request.

Method Summary
`void` | `blockSent()` The http header has been sent.
`void` | `bufferRead(BufferHandle bufHandle)` A buffer has been read, the buffer has been flip:ed before this call is made so position and remaining are valid.
`boolean` | `changesContentSize()` ®return true this handler modifies the content.
`protected void` | `finishData()` This method is used to finish the data for the resource being sent.
`Handler` | `getNewInstance(Connection con, TrafficLoggerHandler tlh, HttpHeader header, BufferHandle bufHandle, HttpHeader webHeader, ResourceSource content, boolean mayCache, boolean mayFilter, long size)` Get a new Handler for the given request made.
`protected boolean` | `mayTransfer()` Check if this handler supports direct transfers.
`protected void` | `modifyBuffer(BufferHandle bufHandle)` This method is used when we are not compressing data.
`protected void` | `prepare()` This method is used to prepare the data for the resource being sent.
`protected void` | `send(BufferHandle bufHandle)`
`void` | `setup(SProperties prop)` setup the handler factory.
`protected void` | `setupHandler()`
`protected void` | `waitForData()`
`protected boolean` | `willCompress(HttpHeader request)`
`protected void` | `writeDataToGZipper(byte[] arr)` Write the current block of data to the gzipper.

Methods inherited from class rabbit.handler.BaseHandler
`addCache, deleteFile, failed, finish, finishedRead, getLogger, handle, httpHeaderSent, mayCacheFromSize, mayRestrictCacheSize, prepareStream, removeCache, send, sendHeader, setPartialContent, timeout, writeCache`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### compress

    protected boolean compress

Constructor Detail

### GZipHandler

    public GZipHandler()

  For creating the factory.

### GZipHandler

    public GZipHandler(Connection con,
                       TrafficLoggerHandler tlh,
                       HttpHeader request,
                       BufferHandle clientHandle,
                       HttpHeader response,
                       ResourceSource content,
                       boolean mayCache,
                       boolean mayFilter,
                       long size,
                       boolean compress)

  Create a new GZipHandler for the given request.

  Parameters:
    `con` - the Connection handling the request.
    `request` - the actual request made.
    `clientHandle` - the client side buffer.
    `response` - the actual response.
    `content` - the resource.
    `mayCache` - May we cache this request?
    `mayFilter` - May we filter this request?
    `size` - the size of the data beeing handled.
    `compress` - if we want this handler to compress or not.

Method Detail

### setupHandler

    protected void setupHandler()

### willCompress

    protected boolean willCompress(HttpHeader request)

### getNewInstance

    public Handler getNewInstance(Connection con,
                                  TrafficLoggerHandler tlh,
                                  HttpHeader header,
                                  BufferHandle bufHandle,
                                  HttpHeader webHeader,
                                  ResourceSource content,
                                  boolean mayCache,
                                  boolean mayFilter,
                                  long size)

  Description copied from interface: `HandlerFactory`
  Get a new Handler for the given request made.

  Specified by:
    `getNewInstance` in interface `HandlerFactory`
  Overrides:
    `getNewInstance` in class `BaseHandler`
  Parameters:
    `con` - the Connection handling the request.
    `tlh` - the Traffic logger handler.
    `header` - the request.
    `bufHandle` - the client side buffer handle (may contain the next request).
    `webHeader` - the response.
    `content` - the resource.
    `mayCache` - if the handler may cache the response.
    `mayFilter` - if the handler may filter the response.
    `size` - the Size of the data beeing handled (-1 = unknown length).

### changesContentSize

    public boolean changesContentSize()

  ®return true this handler modifies the content.

  Specified by:
    `changesContentSize` in interface `Handler`
  Overrides:
    `changesContentSize` in class `BaseHandler`
  Returns:
    true if Content-Lenght may be changed by this handler typically used for handlers that may modify the content. Return false if this handler will not change the size.

### prepare

    protected void prepare()

  Description copied from class: `BaseHandler`
  This method is used to prepare the data for the resource being sent. This method does nothing here.

  Overrides:
    `prepare` in class `BaseHandler`

### finishData

    protected void finishData()

  Description copied from class: `BaseHandler`
  This method is used to finish the data for the resource being sent. This method will send an end chunk if needed and then call finish

  Overrides:
    `finishData` in class `BaseHandler`

### mayTransfer

    protected boolean mayTransfer()

  Check if this handler supports direct transfers.

  Overrides:
    `mayTransfer` in class `BaseHandler`
  Returns:
    this handler always return false.

### blockSent

    public void blockSent()

  Description copied from interface: `BlockSentListener`
  The http header has been sent.

  Specified by:
    `blockSent` in interface `BlockSentListener`
  Overrides:
    `blockSent` in class `BaseHandler`

### waitForData

    protected void waitForData()

### writeDataToGZipper

    protected void writeDataToGZipper(byte[] arr)
                               throws IOException

  Write the current block of data to the gzipper. If you override this method you probably want to override the modifyBuffer(ByteBuffer) as well.

  Parameters:
    `arr` - the data to write to the gzip stream.
  Throws:
    `IOException`

### modifyBuffer

    protected void modifyBuffer(BufferHandle bufHandle)

  This method is used when we are not compressing data. This method will just call "super.bufferRead (buf);"

  Parameters:
    `bufHandle` - the handle to the buffer that just was read.

### send

    protected void send(BufferHandle bufHandle)

### bufferRead

    public void bufferRead(BufferHandle bufHandle)

  Description copied from interface: `BlockListener`
  A buffer has been read, the buffer has been flip:ed before this call is made so position and remaining are valid.

  Specified by:
    `bufferRead` in interface `BlockListener`
  Overrides:
    `bufferRead` in class `BaseHandler`

### setup

    public void setup(SProperties prop)

  Description copied from interface: `HandlerFactory`
  setup the handler factory.

  Specified by:
    `setup` in interface `HandlerFactory`
  Overrides:
    `setup` in class `BaseHandler`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD