Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts2.dispatcher
Class StreamResult

    java.lang.Object
      org.apache.struts2.dispatcher.StrutsResultSupport
          org.apache.struts2.dispatcher.StreamResult

All Implemented Interfaces:
  Result, java.io.Serializable, StrutsStatics

    public class StreamResult

extends StrutsResultSupport

A custom Result type for sending raw data (via an InputStream) directly to the HttpServletResponse. Very useful for allowing users to download content.

This result type takes the following parameters:

- contentType - the stream mime-type as sent to the web browser (default = `text/plain`).
- contentLength - the stream length in bytes (the browser displays a progress bar).
- contentDisposition - the content disposition header value for specifing the file name (default = `inline`, values are typically attachment;filename="document.pdf".
- inputName - the name of the InputStream property from the chained action (default = `inputStream`).
- bufferSize - the size of the buffer to copy from input to output (default = `1024`).
- allowCaching if set to 'false' it will set the headers 'Pragma' and 'Cache-Control' to 'no-cahce', and prevent client from caching the content. (default = `true`)
- contentCharSet if set to a string, ';charset=value' will be added to the content-type header, where value is the string set. If set to an expression, the result of evaluating the expression will be used. If not set, then no charset will be set on the header

These parameters can also be set by exposing a similarly named getter method on your Action. For example, you can provide `getContentType()` to override that parameter for the current action.

Example:

     <result name="success" type="stream">
       <param name="contentType">image/jpeg</param>
       <param name="inputName">imageStream</param>
       <param name="contentDisposition">attachment;filename="document.pdf"</param>
       <param name="bufferSize">1024</param>
     </result>

See Also:
  Serialized Form

Field Summary
`protected boolean` | `allowCaching`
`protected int` | `bufferSize`
`protected java.lang.String` | `contentCharSet`
`protected java.lang.String` | `contentDisposition`
`protected java.lang.String` | `contentLength`
`protected java.lang.String` | `contentType`
`static java.lang.String` | `DEFAULT_PARAM`
`protected java.lang.String` | `inputName`
`protected java.io.InputStream` | `inputStream`
`protected static Logger` | `LOG`

Fields inherited from interface org.apache.struts2.StrutsStatics
`HTTP_REQUEST, HTTP_RESPONSE, PAGE_CONTEXT, SERVLET_CONTEXT, SERVLET_DISPATCHER, STRUTS_ACTION_TAG_INVOCATION, STRUTS_PORTLET_CONTEXT`

Constructor Summary
`StreamResult()`
`StreamResult(java.io.InputStream in)`

Method Summary
`protected void` | `doExecute(java.lang.String finalLocation, ActionInvocation invocation)` Executes the result given a final location (jsp page, action, etc) and the action invocation (the state in which the action was executed).
`boolean` | `getAllowCaching()`
`int` | `getBufferSize()`
`java.lang.String` | `getContentCharSet()`
`java.lang.String` | `getContentDisposition()`
`java.lang.String` | `getContentLength()`
`java.lang.String` | `getContentType()`
`java.lang.String` | `getInputName()`
`protected void` | `resolveParamsFromStack(ValueStack stack, ActionInvocation invocation)` Tries to lookup the parameters on the stack.
`void` | `setAllowCaching(boolean allowCaching)` Set allowCaching to `false` to indicate that the client should be requested not to cache the data stream.
`void` | `setBufferSize(int bufferSize)`
`void` | `setContentCharSet(java.lang.String contentCharSet)`
`void` | `setContentDisposition(java.lang.String contentDisposition)`
`void` | `setContentLength(java.lang.String contentLength)`
`void` | `setContentType(java.lang.String contentType)`
`void` | `setInputName(java.lang.String inputName)`

Methods inherited from class org.apache.struts2.dispatcher.StrutsResultSupport
`conditionalParse, execute, getLastFinalLocation, getLocation, setEncode, setLocation, setParse`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### LOG

    protected static final Logger LOG

### DEFAULT_PARAM

    public static final java.lang.String DEFAULT_PARAM

See Also:
  Constant Field Values

### contentType

    protected java.lang.String contentType

### contentLength

    protected java.lang.String contentLength

### contentDisposition

    protected java.lang.String contentDisposition

### contentCharSet

    protected java.lang.String contentCharSet

### inputName

    protected java.lang.String inputName

### inputStream

    protected java.io.InputStream inputStream

### bufferSize

    protected int bufferSize

### allowCaching

    protected boolean allowCaching

Constructor Detail

### StreamResult

    public StreamResult()

### StreamResult

    public StreamResult(java.io.InputStream in)

Method Detail

### getAllowCaching

    public boolean getAllowCaching()

  Returns:
    Returns the whether or not the client should be requested to allow caching of the data stream.

### setAllowCaching

    public void setAllowCaching(boolean allowCaching)

  Set allowCaching to `false` to indicate that the client should be requested not to cache the data stream. This is set to `false` by default

  Parameters:
    `allowCaching` - Enable caching.

### getBufferSize

    public int getBufferSize()

  Returns:
    Returns the bufferSize.

### setBufferSize

    public void setBufferSize(int bufferSize)

  Parameters:
    `bufferSize` - The bufferSize to set.

### getContentType

    public java.lang.String getContentType()

  Returns:
    Returns the contentType.

### setContentType

    public void setContentType(java.lang.String contentType)

  Parameters:
    `contentType` - The contentType to set.

### getContentLength

    public java.lang.String getContentLength()

  Returns:
    Returns the contentLength.

### setContentLength

    public void setContentLength(java.lang.String contentLength)

  Parameters:
    `contentLength` - The contentLength to set.

### getContentDisposition

    public java.lang.String getContentDisposition()

  Returns:
    Returns the Content-disposition header value.

### setContentDisposition

    public void setContentDisposition(java.lang.String contentDisposition)

  Parameters:
    `contentDisposition` - the Content-disposition header value to use.

### getContentCharSet

    public java.lang.String getContentCharSet()

  Returns:
    Returns the charset specified by the user

### setContentCharSet

    public void setContentCharSet(java.lang.String contentCharSet)

  Parameters:
    `contentCharSet` - the charset to use on the header when sending the stream

### getInputName

    public java.lang.String getInputName()

  Returns:
    Returns the inputName.

### setInputName

    public void setInputName(java.lang.String inputName)

  Parameters:
    `inputName` - The inputName to set.

### doExecute

    protected void doExecute(java.lang.String finalLocation,
                             ActionInvocation invocation)
                      throws java.lang.Exception

  Description copied from class: `StrutsResultSupport`
  Executes the result given a final location (jsp page, action, etc) and the action invocation (the state in which the action was executed). Subclasses must implement this class to handle custom logic for result handling.

  Specified by:
    `doExecute` in class `StrutsResultSupport`
  Parameters:
    `finalLocation` - the location (jsp page, action, etc) to go to.
    `invocation` - the execution state of the action.
  Throws:
    `java.lang.Exception` - if an error occurs while executing the result.
  See Also:
    `StrutsResultSupport.doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation)`

### resolveParamsFromStack

    protected void resolveParamsFromStack(ValueStack stack,
                                          ActionInvocation invocation)

  Tries to lookup the parameters on the stack. Will override any existing parameters

  Parameters:
    `stack` - The current value stack

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.