My web application is creating an XML file. I use the result of the Struts2 stream to control loading, here is the action in struts.xml:
<action name="generateXML" class="navigation.actions.GenerateXML"> <result type="stream"> <param name="contentType">text/xml</param> <param name="inputName">inputStream</param> <param name="bufferSize">1024</param> </result> ... </action>
This creates the part of the "GenerateXML" action class, where the "inputStream" FileInputStream is created:
public String execute() { File xml = new File(filename); ...//fill the file with stuff try { setInputStream(new FileInputStream(xml)); } finally { //inputStream.close(); xml.delete(); } }
Deleting a file will not work because inputStream is not closed yet (this part is commented out). However, if I close it at this moment, the xml file uploaded by the user is empty, since its stream was closed before struts generates the download. Besides using a script that regularly deletes these temporary files on the server, is there a way to close the "inputStream" AFTER struts did their job?
source share