rabbit.handler
Class BaseHandler

java.lang.Object
  |
  +--rabbit.handler.BaseHandler
All Implemented Interfaces:
Handler
Direct Known Subclasses:
GZIPHandler, ImageHandler

public class BaseHandler
extends java.lang.Object
implements Handler

This class is an implementation of the Handler interface. This handler does no filtering, it only sends the data as effective as it can.


Field Summary
protected  java.io.OutputStream cacheStream
          The cache stream if available.
protected  MultiOutputStream clientstream
          The stream to send data to.
protected  Connection con
          The Connection handling the request.
protected  java.io.InputStream contentstream
          The stream to read data from.
protected  NCacheEntry entry
          The cache entry if available.
protected  boolean maycache
          May we cache this request.
protected  boolean mayfilter
          May we filter this request
protected  HTTPHeader request
          The actual request made.
protected  HTTPHeader response
          The actual response.
protected  long size
          The length of the data beeing handled or -1 if unknown.
 
Constructor Summary
BaseHandler(Connection con, HTTPHeader request, HTTPHeader response, java.io.InputStream contentstream, MultiOutputStream clientstream, boolean maycache, boolean mayfilter, long size)
          Create a new BaseHansler for the given request.
 
Method Summary
protected  void addCacheStream()
          Set up the cache stream if available.
protected  void finish()
          Close nesseccary files and adjust the cached files.
protected  void finishStream()
          This method is used to finish the stream for the data being sent.
 void handle()
          Handle the request.
protected  void prepareStream()
          This method is used to prepare the stream for the data being sent.
protected  void removeCache(java.lang.Exception e)
          Remove the cachestream and the cache entry.
protected  void send()
          Send the actual data.
protected  void setPartialContent(long got, long shouldbe)
           
protected  void writeHeader()
          Write the response header
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

con

protected Connection con
The Connection handling the request.


request

protected HTTPHeader request
The actual request made.


response

protected HTTPHeader response
The actual response.


contentstream

protected java.io.InputStream contentstream
The stream to read data from.


clientstream

protected MultiOutputStream clientstream
The stream to send data to.


maycache

protected boolean maycache
May we cache this request.


mayfilter

protected boolean mayfilter
May we filter this request


entry

protected NCacheEntry entry
The cache entry if available.


cacheStream

protected java.io.OutputStream cacheStream
The cache stream if available.


size

protected long size
The length of the data beeing handled or -1 if unknown.

Constructor Detail

BaseHandler

public BaseHandler(Connection con,
                   HTTPHeader request,
                   HTTPHeader response,
                   java.io.InputStream contentstream,
                   MultiOutputStream clientstream,
                   boolean maycache,
                   boolean mayfilter,
                   long size)
Create a new BaseHansler 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

writeHeader

protected void writeHeader()
                    throws java.io.IOException
Write the response header

Throws:
java.io.IOException - if writing the response fails.

addCacheStream

protected void addCacheStream()
                       throws java.io.IOException
Set up the cache stream if available.

Throws:
java.io.IOException - if a cachestream couldnt be set up.

prepareStream

protected void prepareStream()
                      throws java.io.IOException
This method is used to prepare the stream for the data being sent. This method does nothing here.

java.io.IOException

send

protected void send()
             throws java.io.IOException
Send the actual data.

Throws:
java.io.IOException - if reading or writing of the data fails.

setPartialContent

protected void setPartialContent(long got,
                                 long shouldbe)

finishStream

protected void finishStream()
                     throws java.io.IOException
This method is used to finish the stream for the data being sent. This method does nothing here.

java.io.IOException

finish

protected void finish()
               throws java.io.IOException
Close nesseccary files and adjust the cached files. If you override this one, remember to call super.finish ()!

Throws:
java.io.IOException - if closing the files does.

handle

public void handle()
            throws java.io.IOException
Handle the request. A request is made in these steps: writeHeader (); addCacheStream (); prepareStream (); send (); finishStream (); finish ();

Specified by:
handle in interface Handler
Throws:
java.io.IOException - if any of the underlying methods does.

removeCache

protected void removeCache(java.lang.Exception e)
Remove the cachestream and the cache entry. Use this to clean up resources held, but not released due to IOExceptions.

Parameters:
e - the Exception that happened