Question

I have an action in struts 2 where it opens an FileInputStream, reads an image and shows it in a jsp.

The question is that when struts is finished with getting the image, will it automatically take care of the FileInputStream and close() it or the stream is left open?

Was it helpful?

Solution

Struts2 will take care of closing the input stream once it has done the work for you.

Here is the link to the source code and you can very well see that it has been taken care to close the stream.

Struts2 StreamResult Source Code

Here is the code snippet from the same:

 finally {

           if (inputStream != null) inputStream.close();
           if (oOutput != null) oOutput.close();
        }

Hope will give you clear idea how things are going underway.

OTHER TIPS

The result will close the input stream; all the action does is provide the stream. Your code no longer has control of the input stream once the action returns.

Relevant code is in org.apache.struts2.dispatcher.StreamResult:doExecute.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top