Package org.apache.commons.io.output
Class ClosedWriter
- java.lang.Object
-
- java.io.Writer
-
- org.apache.commons.io.output.ClosedWriter
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
public class ClosedWriter extends Writer
Throws an exception on all attempts to write withclose()implemented as a noop.Typically uses of this class include testing for corner cases in methods that accept a writer and acting as a sentinel value instead of a
nullwriter.- Since:
- 2.7
-
-
Field Summary
Fields Modifier and Type Field Description static ClosedWriterCLOSED_WRITERA singleton.
-
Constructor Summary
Constructors Constructor Description ClosedWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()Throws anIOExceptionto indicate that the stream is closed.voidwrite(char[] cbuf, int off, int len)Throws anIOExceptionto indicate that the writer is closed.
-
-
-
Field Detail
-
CLOSED_WRITER
public static final ClosedWriter CLOSED_WRITER
A singleton.
-
-
Method Detail
-
write
public void write(char[] cbuf, int off, int len) throws IOExceptionThrows anIOExceptionto indicate that the writer is closed.- Specified by:
writein classWriter- Parameters:
cbuf- ignoredoff- ignoredlen- ignored- Throws:
IOException- always thrown
-
flush
public void flush() throws IOExceptionThrows anIOExceptionto indicate that the stream is closed.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- always thrown
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
-