net.sourceforge.stripes.action
Class StreamingResolution

java.lang.Object
  extended by net.sourceforge.stripes.action.StreamingResolution
All Implemented Interfaces:
Resolution

public class StreamingResolution
extends Object
implements Resolution

Resolution for streaming data back to the client (in place of forwarding the user to another page). Designed to be used for streaming non-page data such as generated images/charts and XML islands.

Optionally supports the use of a file name which, if set, will cause a Content-Disposition header to be written to the output, resulting in a "Save As" type dialog box appearing in the user's browser. If you do not wish to supply a file name, but wish to acheive this behaviour, simple supply a file name of "".

Author:
Tim Fennell

Constructor Summary
StreamingResolution(String contentType, InputStream inputStream)
          Constructor that builds a StreamingResolution that will stream binary data back to the client and identify the data as being of the specified content type.
StreamingResolution(String contentType, Reader reader)
          Constructor that builds a StreamingResolution that will stream character data back to the client and identify the data as being of the specified content type.
 
Method Summary
 void execute(HttpServletRequest request, HttpServletResponse response)
          Streams data from the InputStream or Reader to the response's OutputStream or PrinterWriter, using a moderately sized buffer to ensure that the operation is reasonable efficient.
 StreamingResolution setFilename(String filename)
          Sets the filename that will be the default name suggested when the user is prompted to save the file/stream being sent back.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamingResolution

public StreamingResolution(String contentType,
                           InputStream inputStream)
Constructor that builds a StreamingResolution that will stream binary data back to the client and identify the data as being of the specified content type.

Parameters:
contentType - the content type of the data in the stream (e.g. image/png)
inputStream - an InputStream from which to read the data to return to the client

StreamingResolution

public StreamingResolution(String contentType,
                           Reader reader)
Constructor that builds a StreamingResolution that will stream character data back to the client and identify the data as being of the specified content type.

Parameters:
contentType - the content type of the data in the stream (e.g. text/xml)
reader - a Reader from which to read the character data to return to the client
Method Detail

setFilename

public StreamingResolution setFilename(String filename)
Sets the filename that will be the default name suggested when the user is prompted to save the file/stream being sent back. If the stream is not for saving by the user (i.e. it should be displayed or used by the browser) this value should not be set.

Parameters:
filename - the default filename the user will see
Returns:
StreamingResolution so that this method call can be chained to the constructor and returned

execute

public void execute(HttpServletRequest request,
                    HttpServletResponse response)
             throws Exception
Streams data from the InputStream or Reader to the response's OutputStream or PrinterWriter, using a moderately sized buffer to ensure that the operation is reasonable efficient. Once the InputStream or Reader signaled the end of the stream, close() is called on it.

Specified by:
execute in interface Resolution
Parameters:
request - the HttpServletRequest being processed
response - the paired HttpServletReponse
Throws:
IOException - if there is a problem accessing one of the streams or reader/writer objects used.
Exception - exceptions of any type may be thrown if the Resolution cannot be executed as intended


© Copyright 2005, Stripes Development Team.