tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rehtron <nert...@gmail.com>
Subject Re: Servlet input/output streams
Date Thu, 23 Jun 2011 02:33:20 GMT
Hi

You may use decorator pattern to decorate the input & output stream from
Servlet to a UnclosableInputStream & UnclosableOutputStream,

public class UnclosableInputStream extends java.io.FilterInputStream {

public UnclosableInputStream(InputStream inputStream) {
super(inputStream);
}

@Override
public void close() {
// do nothing.
}

}

InputStream inputStream = new
UnclosableInputStream(servlet.getInputStream());

inputStream.read(); // invoke the decorated ServletInputStream.
inputStream.close() // do nothing

Hope it'll helpful for you.

Zijian.

2011/6/22 Ronald Albury <ronalbury@gmail.com>

> My understanding is that I should *not* close the servlet input/output
> streams (if you don't open them - you shouldn't close them)
>
> But what if I have wrapped those streams inside other streams that I want
> to
> close?  Let's say I have several layers of object streams, cipher streams,
> compression streams, etc.  Will it be ok to call close on the outer-most
> stream, or do I need to rely on the 'flush' and 'finish' methods on these
> wrapping streams.
>
> What about the potential for memory leaks - or is that mostly just an issue
> on the inner-most stream that actually does the physical I/O?
>
> Thank you for taking the time to read this email.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message