|
[
Permlink
| « Hide
]
Martin Crawford added a comment - 27/Jul/04 01:54 PM
Here is the file.
Realized that probably the input stream should be closed after the data is transfered to the output stream. Not sure what memory leak issues might occur otherwise. So far I haven't encountered any in my application using this but it would seem to be good practice.
with webwork 2.1.5, I need to add the parameter "parse" to avoid NPE in xwork TextParseUtil.
<result name="success" type="stream"> <param name="parse">false</param> <param name="contentType">image/png</param> <param name="inputName">imageStream</param> <param name="bufferSize">1024</param> </result> On 2.1.7 I had a problem with the stream not being closed. I need to delete files that had been read by the stream later on, and had issues because they were in use. I implemented the following fix in the class:
protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { InputStream oInput = null; OutputStream oOutput = null; try{ // Find the inputstream from the invocation variable stack oInput = (InputStream) invocation.getStack().findValue(conditionalParse(inputName, invocation)); // Find the Response in context HttpServletResponse oResponse = (HttpServletResponse) invocation.getInvocationContext().get(HTTP_RESPONSE); // Set the content type oResponse.setContentType(conditionalParse(contentType, invocation)); // Set the content-disposition if (contentDisposition != null) { oResponse.addHeader("Content-disposition", conditionalParse(contentDisposition, invocation)); } // Get the outputstream oOutput = oResponse.getOutputStream(); // Copy input to output byte[] oBuff = new byte[bufferSize]; int iSize = 0; while (-1 != (iSize = oInput.read(oBuff))) { oOutput.write(oBuff, 0, iSize); } // Flush oOutput.flush(); }finally{ if (oInput != null)oInput.close(); if (oOutput != null)oOutput.close(); } } |
||||||||||||||||||||||||||||||||||||||||||