Package eu.simuline.octave.util
Class NoCloseWriter
- java.lang.Object
-
- java.io.Writer
-
- eu.simuline.octave.util.NoCloseWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public final class NoCloseWriter extends Writer
Will protect a Writer from being closed byclose(), useful for protecting stdout and stderr from being closed. Trying to close viaclose()results in loosing connection whereasreallyClose()really closes the writer.- Author:
- Kim Hansen
-
-
Constructor Summary
Constructors Constructor Description NoCloseWriter(Writer writer)Create a NoCloseWriter that will protect writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Flushes the writer and looses the connection to it.voidflush()voidreallyClose()Really closes the underlying writer, with one exception ;-).voidwrite(char[] cbuf, int off, int len)
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
writer
private Writer writer
A writer ornull. The latter is the case if initialized withnull, or if tried to close viaclose(). In the latter case it is not even possible to close withreallyClose().
-
-
Method Detail
-
write
public void write(char[] cbuf, int off, int len) throws IOException- Specified by:
writein classWriter- Throws:
IOException
-
flush
public void flush() throws IOException- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
public void close() throws IOExceptionFlushes the writer and looses the connection to it. No close and also in future no close possible.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- from the underlying writer.- See Also:
reallyClose()
-
reallyClose
public void reallyClose() throws IOExceptionReally closes the underlying writer, with one exception ;-).- Throws:
IOException- from the underlying writer.NullPointerException- if the NoCloseWriter has been closed viaclose().
-
-