|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sourceforge.stripes.action.StreamingResolution
public class StreamingResolution
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 achieve this behaviour, simple supply a file name of "".
StreamingResolution is designed to be subclassed where necessary to provide streaming output where the data being streamed is not contained in an InputStream or Reader. This would normally be done using an anonymous inner class as follows:
return new StreamingResolution("text/xml") {
public void stream(HttpServletResponse response) throws Exception {
// custom output generation code
response.getWriter().write(...);
// or
response.getOutputStream().write(...);
}
}.setFilename("your-filename.xml");
| Constructor Summary | |
|---|---|
StreamingResolution(String contentType)
Constructor only to be used when subclassing the StreamingResolution (usually using an anonymous inner class. |
|
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. |
|
StreamingResolution(String contentType,
String output)
Constructor that builds a StreamingResolution that will stream character data from a String 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. |
void |
setCharacterEncoding(String characterEncoding)
Sets the character encoding that will be set on the request when executing this resolution. |
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. |
protected void |
stream(HttpServletResponse response)
Does the actual streaming of data through the response. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public StreamingResolution(String contentType)
contentType - the content type of the data in the stream (e.g. image/png)
public StreamingResolution(String contentType,
InputStream inputStream)
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
public StreamingResolution(String contentType,
Reader reader)
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
public StreamingResolution(String contentType,
String output)
contentType - the content type of the data in the stream (e.g. text/xml)output - a String to stream back to the client| Method Detail |
|---|
public StreamingResolution setFilename(String filename)
filename - the default filename the user will see
public void setCharacterEncoding(String characterEncoding)
characterEncoding - the character encoding to use instead of the default
public final void execute(HttpServletRequest request,
HttpServletResponse response)
throws Exception
execute in interface Resolutionrequest - the HttpServletRequest being processedresponse - the paired HttpServletResponse
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
protected void stream(HttpServletResponse response)
throws Exception
Does the actual streaming of data through the response. If subclassed, this method should be overridden to stream back data other than data supplied by an InputStream or a Reader supplied to a constructor.
If an InputStream or Reader was supplied to a constructor, this implementation uses a moderately sized buffer to stream data from it to the response to make the operation reasonably efficient, and closes the InputStream or the Reader. If an IOException occurs when closing it, that exception will be logged as a warning, and not thrown to avoid masking a possibly previously thrown exception.
response - the HttpServletResponse from which either the output stream or writer can be
obtained
Exception - if any problems arise when streaming data
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||