Java – does closing bufferedoutputstream also close the underlying OutputStream?
I call response Getoutputstream () streams binary data (extracted from the database as a CLOB CSV file) to the browser, and usually wraps the OutputStream in bufferedoutputstream when copying data
Should I close bufferedoutputstream or the underlying OutputStream?
[additional question: do I need to use bufferedoutputstream in this case?
Solution
Yes, it closes it About whether you should close it - what other response streams do you expect to write? If not, I think it's good to close it If you don't turn it off, you should obviously flush it - but I doubt you can figure it out for yourself:)
This behavior is actually inherited from filteroutputstream FilterOutputStream. JavaDocs status of close:
As for whether you should buffer it - I don't know if it's well defined It may be buried somewhere in the servlet specification - or even configured (sometimes you really don't want to buffer, but if you can buffer the entire response, it means you can provide a better error page, and if there's a problem, ve starts writing)