3

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?

elixenide
  • 44,308
  • 16
  • 74
  • 100
Panos
  • 7,227
  • 13
  • 60
  • 95

2 Answers2

2

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
1

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.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204