Package org.apache.struts.extras.actions
Class DownloadAction
java.lang.Object
org.apache.struts.action.Action
org.apache.struts.extras.actions.BaseAction
org.apache.struts.extras.actions.DownloadAction
- All Implemented Interfaces:
 Serializable
This is an abstract base class that minimizes the amount of special coding
 that needs to be written to download a file. All that is required to use
 this class is to extend it and implement the 
getStreamInfo()
 method so that it returns the relevant information for the file (or other
 stream) to be downloaded. Optionally, the getBufferSize()
 method may be overridden to customize the size of the buffer used to
 transfer the file.- Since:
 - Struts 1.2.6
 - See Also:
 
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA concrete implementation of theStreamInfointerface which simplifies the downloading of a file from the disk.static classA concrete implementation of theStreamInfointerface which simplifies the downloading of a web application resource.static interfaceThe information on a file, or other stream, to be downloaded by theDownloadAction. - 
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intIf thegetBufferSize()method is not overridden, this is the buffer size that will be used to transfer the data to the servlet output stream.Fields inherited from class org.apache.struts.extras.actions.BaseAction
messages - 
Constructor Summary
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionintcopy(InputStream input, OutputStream output) Copy bytes from anInputStreamto anOutputStream.execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it).protected intReturns the size of the buffer to be used in transferring the data to the servlet output stream.protected abstract DownloadAction.StreamInfogetStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) Returns the information on the file, or other stream, to be downloaded by this action.Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet 
- 
Field Details
- 
DEFAULT_BUFFER_SIZE
protected static final int DEFAULT_BUFFER_SIZEIf thegetBufferSize()method is not overridden, this is the buffer size that will be used to transfer the data to the servlet output stream.- See Also:
 
 
 - 
 - 
Constructor Details
- 
DownloadAction
public DownloadAction() 
 - 
 - 
Method Details
- 
getStreamInfo
protected abstract DownloadAction.StreamInfo getStreamInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception Returns the information on the file, or other stream, to be downloaded by this action. This method must be implemented by an extending class.- Parameters:
 mapping- The ActionMapping used to select this instance.form- The optional ActionForm bean for this request (if any).request- The HTTP request we are processing.response- The HTTP response we are creating.- Returns:
 - The information for the file to be downloaded.
 - Throws:
 Exception- if an exception occurs.
 - 
getBufferSize
protected int getBufferSize()Returns the size of the buffer to be used in transferring the data to the servlet output stream. This method may be overridden by an extending class in order to customize the buffer size.- Returns:
 - The size of the transfer buffer, in bytes.
 
 - 
execute
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return anActionForwardinstance describing where and how control should be forwarded, ornullif the response has already been completed.- Overrides:
 executein classAction- Parameters:
 mapping- The ActionMapping used to select this instance.form- The optional ActionForm bean for this request (if any).request- The HTTP request we are processing.response- The HTTP response we are creating.- Returns:
 - The forward to which control should be transferred, or
         
nullif the response has been completed. - Throws:
 Exception- if an exception occurs.
 - 
copy
Copy bytes from anInputStreamto anOutputStream.- Parameters:
 input- TheInputStreamto read from.output- TheOutputStreamto write to.- Returns:
 - the number of bytes copied
 - Throws:
 IOException- In case of an I/O problem
 
 -