%bte.doc super="item.bte" %> <%bte.tpl name=pageTitle%>NoClose Streams<%/bte.tpl%> <%bte.tpl name=description%>Create streams that cannot be closed with the regular close() mechanism.<%/bte.tpl%> <%bte.tpl name=keywords%>no close stream, noclosestream, unclosable stream library, java stream that can't be closed<%/bte.tpl%> <%bte.tpl name=content%>
Create streams that cannot be closed with the normal close() mechanism. Instead, a reallyClose() method is provided while the close() method does nothing.
This is useful when you have a stream to pass to methods that either read or write using the stream. If any of the methods call the stream's close method before you are done with the stream, this class is useful. Simply wrap your stream in one of the NoClose Streams, and pass that around. When the other method calls the close method it will have no effect. You can later close your stream by calling the reallyClose() method.
[Download /w Source | Version History | Browse Source | Documentation]
// prevent system.in from being closed NoCloseInputStream in = new NoCloseInputStream(System.in); // pass in to other classes: /* somebodyelse.dosomething(in); */ in.reallyClose();
[Download /w Source | Version History | Browse Source | Documentation]
// prevent system.out from being closed NoCloseOutputStream out = new NoCloseOutputStream(System.out); // pass out to other classes: /* somebodyelse.dosomething(out); */ out.reallyClose();
[Download /w Source | Version History | Browse Source | Documentation]
// prevent a file reader from being closed NoCloseReader in = new NoCloseReader(new FileReader("file.txt")); // pass in to other classes: /* somebodyelse.dosomething(in); */ in.reallyClose();
[Download /w Source | Version History | Browse Source | Documentation]
// prevent a file writer from being closed NoCloseWriter out = new NoCloseWriter(new FileWriter("file.txt")); // pass out to other classes: /* somebodyelse.dosomething(out); */ out.reallyClose();
[Download /w Source | Version History | Browse Source | Documentation]