문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top