au.com.whitesquare.waf.command.response
Class FileServingResponse

java.lang.Object
  extended byau.com.whitesquare.waf.command.Response
      extended byau.com.whitesquare.waf.command.response.FileServingResponse

public class FileServingResponse
extends Response


Last Modified $Date: 2005/09/12 12:08:45 $

Version:
$Revision: 1.2 $
Author:
Steve Mactaggart

Field Summary
 
Fields inherited from class au.com.whitesquare.waf.command.Response
servletContext
 
Constructor Summary
FileServingResponse()
           
 
Method Summary
 void close()
          This method closes up any open resources required to process the content to be returned to the user.
 byte[] getChunk()
          Retreives the actual content from the data source.
 String getClientFileName()
          Retreives the file name that the client will save this file as.
 String getContentType()
          Retreives the content type that the response will be configured with.
 String getFileName()
          Returns the name of the file on disk that will be served to the client.
 boolean hasMore()
          Returns if there is any more content available to be sent on the stream.
 void open()
          This method is called to open the input stream and prepare the response to serve the content out the stream.
 void sendResponse(HttpServletRequest req, HttpServletResponse resp)
           
 void setClientFileName(String clientFileName)
          Configures the name the client will treat this file as.
 void setContentType(String contentType)
          Configures the Content Type of the response in relation to the data being returned.
 void setFileName(String fileName)
          This is the absolute file name on disk to be retreived.
 
Methods inherited from class au.com.whitesquare.waf.command.Response
init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileServingResponse

public FileServingResponse()
Method Detail

open

public void open()
          throws FileNotFoundException
This method is called to open the input stream and prepare the response to serve the content out the stream.

Throws:
FileNotFoundException - if the filename cannot be found on the file system.

close

public void close()
           throws IOException
This method closes up any open resources required to process the content to be returned to the user.

Throws:
IOException - if closing the stream fails.

hasMore

public boolean hasMore()
Returns if there is any more content available to be sent on the stream. A call to this method should be followed with a call to getChunk() to retreive the next chunk of data to be returned. The getChunk() method will update the status of more and then this method can be called again to see if there is still more information.
This method is best used inside a while loop, with a priming getChunk() call outside and another inside the while loop.

Returns:
if there is more data to be read from getChunk()

getChunk

public byte[] getChunk()
                throws IOException
Retreives the actual content from the data source. This method returns 2048 bytes of data per read, and once the data source has been exhausted will update the status of hasMore() to be false.

Returns:
the byte[] containing the next chunk of data to be served.
Throws:
IOException - if any inputstream reading fails.

getFileName

public String getFileName()
Returns the name of the file on disk that will be served to the client.

Returns:
Returns the fileName.

setFileName

public void setFileName(String fileName)
This is the absolute file name on disk to be retreived. The file name must be absolute and accessible by the JVM that is running this application.

Parameters:
fileName - The fileName to set.

getContentType

public String getContentType()
Retreives the content type that the response will be configured with.

Returns:
Returns the contentType.

setContentType

public void setContentType(String contentType)
Configures the Content Type of the response in relation to the data being returned. For images use a 'images/xxx' content type, pdf's use 'application/pdf' or any other valid MIME type.

Parameters:
contentType - The contentType to set.

getClientFileName

public String getClientFileName()
Retreives the file name that the client will save this file as.

Returns:
Returns the clientFileName.

setClientFileName

public void setClientFileName(String clientFileName)
Configures the name the client will treat this file as. If no client file name is supplied then the client will not recieve a file name at all.
This is a useful method if the application wants to change the name of the file being served from what it is known as on disk.

Parameters:
clientFileName - The clientFileName to set.

sendResponse

public void sendResponse(HttpServletRequest req,
                         HttpServletResponse resp)
                  throws Exception
Specified by:
sendResponse in class Response
Parameters:
req -
resp -
Throws:
Exception


Copyright © 2004 Whitesquare Software. All Rights Reserved.