IIRC, when you close a Servlet, the ServletIn/OutputStreams get closed
for you as well. However, that's not good enough if you're wrapping
those into a non-direct-writethrough stream, such as GzipOutputStream,
as Christian Catchpole mentioned.

Therefore, close em. Be aware that the close calls, especially on the
ServletOutputStream, can generate exceptions; the servlet container
and the network can both simply be buffering your output, and the close
() then exceptions when the resulting flush down the pipe runs into an
I/O issue. Remember the mantra:

InputStream.close(): stupid.

OutputStream.close(): Even more important that .write()'s IOExceptions
- assume the entire write operation failed if you get one.

On May 26, 1:37 am, Michael Neale <[email protected]> wrote:
> You know it has been many years, but I still find that joke funny -
> everytime I write "flush()" I have a little smile.
>
> On May 26, 8:16 am, Viktor Klang <[email protected]> wrote:
>
> > I'd agree that flushing is a rather good practice, and while one's at it,
> > the mrs' generally appreciate having the toilet seat lid down.
>
> > On Tue, May 26, 2009 at 12:12 AM, Christian Catchpole <
>
> > [email protected]> wrote:
>
> > > My expectation would be to close() as it should be abstracted from any
> > > real IO stream and closing should do no harm.  In fact there can be
> > > cases where harm is done if you don't close, or at least flush.  I
> > > wrote a method to wrap the OutputStream with a compressing stream if
> > > the client would accept it.  This would be the same for any buffered
> > > stream that you wrap around the OutputStream.  You will have to flush
> > > it as the container closing the stream it handed you is not going to
> > > flush your wrapper stream.  And a close is as good as a flush.
>
> > > I do accept that I've often never closed on non-wrapped streams and
> > > it's done no harm.
>
> > > As for Brian's case, I would expect that closing the stream has "gone
> > > too far" closing some underlying stream prematurely.
>
> > --
> > Viktor Klang
> > Rockstar Developer
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to