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

## rabbit.handler
Class ImageHandler

    java.lang.Object
      rabbit.handler.BaseHandler
          rabbit.handler.ImageHandler

All Implemented Interfaces:
  Handler, HandlerFactory, Logger

    public class ImageHandler

extends BaseHandler

This class filters images to low quality jpegs.

Field Summary

Fields inherited from class rabbit.handler.BaseHandler
`cacheStream, clientstream, con, contentstream, entry, maycache, mayfilter, request, response, size`

Fields inherited from interface rabbit.util.Logger
`ALL, DEBUG, ERROR, FATAL, INFO, MSG, WARN`

Constructor Summary
`ImageHandler()`
`ImageHandler(Connection con, HTTPHeader request, HTTPHeader response, HTTPInputStream contentstream, MultiOutputStream clientstream, boolean maycache, boolean mayfilter, long size)` Create a new ImageHansler for the given request.

Method Summary
`void` | `addCacheStream()` Set up the cache stream if available.
`protected void` | `convertImage()` Convert the image into a low quality jpeg.
`protected void` | `finish()` clear up the mess we made (remove intermediate files etc).
`Handler` | `getNewInstance(Connection connection, HTTPHeader header, HTTPHeader webheader, HTTPInputStream contentStream, MultiOutputStream out, boolean maycache, boolean mayfilter, long size)` Get a new Handler for the given request made.
`protected boolean` | `mayCacheFromSize()` Images needs to be cacheable to be compressed.
`protected boolean` | `mayRestrictCacheSize()` Check if this handler may force the cached resource to be less than the cache max size.
`protected void` | `readImage()` Read in the image
`protected void` | `removeCache(java.lang.Exception e)` Remove the cachestream and the cache entry.
`void` | `setup(Logger logger, SProperties prop)` Setup this class.
`protected void` | `tryconvert()` Try to convert the image.
`protected void` | `writeHeader()` Write the response header

Methods inherited from class rabbit.handler.BaseHandler
`clientStreamHasCache, finishStream, getFactory, handle, logError, logError, prepareStream, send, setPartialContent, writeData`

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

Constructor Detail

### ImageHandler

    public ImageHandler()

### ImageHandler

    public ImageHandler(Connection con,
                        HTTPHeader request,
                        HTTPHeader response,
                        HTTPInputStream contentstream,
                        MultiOutputStream clientstream,
                        boolean maycache,
                        boolean mayfilter,
                        long size)

  Create a new ImageHansler for the given request.

  Parameters:
    `con` - the Connection handling the request.
    `request` - the actual request made.
    `response` - the actual response.
    `contentstream` - the stream to read data from.
    `clientstream` - the stream to write data to.
    `maycache` - May we cache this request?
    `mayfilter` - May we filter this request?
    `size` - the size of the data beeing handled.

Method Detail

### getNewInstance

    public Handler getNewInstance(Connection connection,
                                  HTTPHeader header,
                                  HTTPHeader webheader,
                                  HTTPInputStream contentStream,
                                  MultiOutputStream out,
                                  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:
    `connection` - the Connection handling the request.
    `header` - the request.
    `webheader` - the response.
    `contentStream` - the data to read.
    `out` - the client (and possibly the cache).
    `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).

### mayCacheFromSize

    protected boolean mayCacheFromSize()

  Images needs to be cacheable to be compressed.

  Overrides:
    `mayCacheFromSize` in class `BaseHandler`
  Returns:
    true

### mayRestrictCacheSize

    protected boolean mayRestrictCacheSize()

  Check if this handler may force the cached resource to be less than the cache max size.

  Overrides:
    `mayRestrictCacheSize` in class `BaseHandler`
  Returns:
    false

### readImage

    protected void readImage()
                      throws java.io.IOException

  Read in the image

  Throws:
    `java.io.IOException` - if reading of the image fails.

### convertImage

    protected void convertImage()
                         throws java.io.IOException

  Convert the image into a low quality jpeg.

  Throws:
    `java.io.IOException` - if conversion fails.

### tryconvert

    protected void tryconvert()
                       throws java.io.IOException

  Try to convert the image. This is done like this:

        super.addCacheStream ();
        readImage();
        convertImage();
        clientstream.removeOutputStream (cacheStream);

  We have to use the cachefile to convert the image, and if we convert it we dont want to write the file to the cache later on.

  Throws:
    `java.io.IOException`

### writeHeader

    protected void writeHeader()
                        throws java.io.IOException

  Write the response header

  Overrides:
    `writeHeader` in class `BaseHandler`
  Throws:
    `java.io.IOException` - if writing the response fails.

### addCacheStream

    public void addCacheStream()
                        throws java.io.IOException

  Set up the cache stream if available.

  Overrides:
    `addCacheStream` in class `BaseHandler`
  Throws:
    `java.io.IOException` - if a cachestream couldnt be set up.

### finish

    protected void finish()
                   throws java.io.IOException

  clear up the mess we made (remove intermediate files etc).

  Overrides:
    `finish` in class `BaseHandler`
  Throws:
    `java.io.IOException` - if cleaning fails.

### removeCache

    protected void removeCache(java.lang.Exception e)

  Remove the cachestream and the cache entry.

  Overrides:
    `removeCache` in class `BaseHandler`
  Parameters:
    `e` - the Exception that happened

### setup

    public void setup(Logger logger,
                      SProperties prop)

  Setup this class.

  Specified by:
    `setup` in interface `HandlerFactory`
  Overrides:
    `setup` in class `BaseHandler`
  Parameters:
    `prop` - the properties of this class.

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