org.japtproxy.misc
Class IOHandler

java.lang.Object
  extended by org.japtproxy.misc.IOHandler

public class IOHandler
extends java.lang.Object

The IOHandler utility class is responsible for the IO operation between fetchers and pools.

Version:
$LastChangedRevision: 116 $
Author:
Oliver J. Siegmar

Field Summary
protected  FetcherFactory fetcherFactory
          The FetcherFactory instance.
 
Constructor Summary
IOHandler()
           
 
Method Summary
protected  int copy(java.io.InputStream is, java.io.OutputStream sendOs, java.io.OutputStream saveOs)
          Copies data from an InputStream to two OutputStreams.
protected  boolean isNewVersionCheckRequired(java.lang.String resourceName)
          Checks if a new version check is required for a specific resource.
protected  boolean isResourceImmutable(java.lang.String resourceName)
          Detects if a resource is immutable or not.
 boolean sendAndSave(RequestedData requestedData, PoolObject poolObject, java.net.URL targetResource, javax.servlet.http.HttpServletResponse res)
          This method is responsible for fetching remote data (if needed) and sending the data (locally stored, or remotely fetched) to the client.
protected  void sendLocalFile(PoolObject poolObject, long requestModifiedSince, javax.servlet.http.HttpServletResponse res)
          Sends a locally stored pool object to the client.
 void setFetcherFactory(FetcherFactory fetcherFactory)
           
 void setImmutableFilePatterns(java.util.regex.Pattern[] immutableFilePatterns)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fetcherFactory

protected FetcherFactory fetcherFactory
The FetcherFactory instance.

Constructor Detail

IOHandler

public IOHandler()
Method Detail

setImmutableFilePatterns

public void setImmutableFilePatterns(java.util.regex.Pattern[] immutableFilePatterns)

setFetcherFactory

public void setFetcherFactory(FetcherFactory fetcherFactory)

copy

protected int copy(java.io.InputStream is,
                   java.io.OutputStream sendOs,
                   java.io.OutputStream saveOs)
            throws java.io.IOException
Copies data from an InputStream to two OutputStreams. This is used to send package data to client and storage.

Parameters:
is - the InputStream to read from
sendOs - the OutputStream where the data should be sent to
saveOs - the storage OutputStream where the data should be written
Returns:
the amount of bytes copyied from the InputStream to the OutputStreams
Throws:
java.io.IOException - is thrown if a problem occured while copying data

isResourceImmutable

protected boolean isResourceImmutable(java.lang.String resourceName)
Detects if a resource is immutable or not. This test is performed by checking the resource name against a list of known immutable patterns.

Parameters:
resourceName - the resource name
Returns:
true if the resource is immutable

isNewVersionCheckRequired

protected boolean isNewVersionCheckRequired(java.lang.String resourceName)
Checks if a new version check is required for a specific resource.

Parameters:
resourceName - the resource name to check if a version check is required for
Returns:
if a new version check is required

sendLocalFile

protected void sendLocalFile(PoolObject poolObject,
                             long requestModifiedSince,
                             javax.servlet.http.HttpServletResponse res)
                      throws java.io.IOException
Sends a locally stored pool object to the client. This method will send HTTP status code 304 (not modified) if the client sent a 'If-Modified-Since' header and the pool object wasn't modified since that date.

Parameters:
poolObject - the pool object to sent
requestModifiedSince - the "If-Modified-Since" header
res - the HttpServletResponse object
Throws:
java.io.IOException - is thrown if a problem occured while sending data

sendAndSave

public boolean sendAndSave(RequestedData requestedData,
                           PoolObject poolObject,
                           java.net.URL targetResource,
                           javax.servlet.http.HttpServletResponse res)
                    throws java.io.IOException,
                           ResourceUnavailableException,
                           InitializationException
This method is responsible for fetching remote data (if needed) and sending the data (locally stored, or remotely fetched) to the client.

Parameters:
requestedData - the requested data
poolObject - the pool object
targetResource - the remote resource link
res - the HttpServletResponse object
Returns:
true if the file was sent from cache, false otherwise
Throws:
java.io.IOException - is thrown if a problem occured while sending data
ResourceUnavailableException - is thrown if the resource was not found
InitializationException


Copyright © 2006-2008. All Rights Reserved.