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 void
close()
Flushes the writer and looses the connection to it.void
flush()
void
reallyClose()
Really closes the underlying writer, with one exception ;-).void
write(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:
write
in classWriter
- Throws:
IOException
-
flush
public void flush() throws IOException
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
public void close() throws IOException
Flushes the writer and looses the connection to it. No close and also in future no close possible.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
- from the underlying writer.- See Also:
reallyClose()
-
reallyClose
public void reallyClose() throws IOException
Really closes the underlying writer, with one exception ;-).- Throws:
IOException
- from the underlying writer.NullPointerException
- if the NoCloseWriter has been closed viaclose()
.
-
-