Package org.apache.commons.io.output
Class ClosedWriter
- java.lang.Object
-
- java.io.Writer
-
- org.apache.commons.io.output.ClosedWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class ClosedWriter extends java.io.WriterThrows 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 java.io.IOExceptionThrows anIOExceptionto indicate that the writer is closed.- Specified by:
writein classjava.io.Writer- Parameters:
cbuf- ignoredoff- ignoredlen- ignored- Throws:
java.io.IOException- always thrown
-
flush
public void flush() throws java.io.IOExceptionThrows anIOExceptionto indicate that the stream is closed.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException- always thrown
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException
-
-