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.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
null
writer.- Since:
- 2.7
-
-
Field Summary
Fields Modifier and Type Field Description static ClosedWriter
CLOSED_WRITER
A singleton.
-
Constructor Summary
Constructors Constructor Description ClosedWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
void
flush()
Throws anIOException
to indicate that the stream is closed.void
write(char[] cbuf, int off, int len)
Throws anIOException
to 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.IOException
Throws anIOException
to indicate that the writer is closed.- Specified by:
write
in classjava.io.Writer
- Parameters:
cbuf
- ignoredoff
- ignoredlen
- ignored- Throws:
java.io.IOException
- always thrown
-
flush
public void flush() throws java.io.IOException
Throws anIOException
to indicate that the stream is closed.- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
- Throws:
java.io.IOException
- always thrown
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
- Throws:
java.io.IOException
-
-