All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.Ostermiller.util.NoCloseStream.bte Maven / Gradle / Ivy

Go to download

Open source (GPL) Java utilities maintained by Stephen Ostermiller with help from many contributors.

The newest version!
<%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.

<%/bte.tpl%> <%bte.tpl name=content%>

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.

NoCloseStream

Interface for all four of the following classes.

NoCloseInputStream

Example

// prevent system.in from being closed
NoCloseInputStream in = new NoCloseInputStream(System.in);
// pass in to other classes:
/* somebodyelse.dosomething(in); */
in.reallyClose();

NoCloseOutputStream

Example

// prevent system.out from being closed
NoCloseOutputStream out = new NoCloseOutputStream(System.out);
// pass out to other classes:
/* somebodyelse.dosomething(out); */
out.reallyClose();

NoCloseReader

Example

// 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();

NoCloseWriter

Example

// 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();
<%/bte.tpl%> <%bte.tpl name=linkNoCloseStream%>NoClose Streams <%/bte.tpl%> <%/bte.doc%>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy