Package org.apache.commons.io.output
Class BrokenWriter
- java.lang.Object
-
- java.io.Writer
-
- org.apache.commons.io.output.BrokenWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class BrokenWriter extends java.io.WriterAlways throws an exception from allWritermethods whereIOExceptionis declared.This class is mostly useful for testing error handling.
- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description static BrokenWriterINSTANCEThe singleton instance using a default IOException.
-
Constructor Summary
Constructors Constructor Description BrokenWriter()Constructs a new writer that always throws anIOException.BrokenWriter(java.io.IOException exception)Deprecated.BrokenWriter(java.lang.Throwable exception)Constructs a new writer that always throws the given exception.BrokenWriter(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)Constructs a new writer that always throws the supplied exception.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Throws the configured exception.voidflush()Throws the configured exception.voidwrite(char[] cbuf, int off, int len)Throws the configured exception.
-
-
-
Field Detail
-
INSTANCE
public static final BrokenWriter INSTANCE
The singleton instance using a default IOException.- Since:
- 2.12.0
-
-
Constructor Detail
-
BrokenWriter
public BrokenWriter()
Constructs a new writer that always throws anIOException.
-
BrokenWriter
@Deprecated public BrokenWriter(java.io.IOException exception)
Deprecated.Constructs a new writer that always throws the given exception.- Parameters:
exception- the exception to be thrown.
-
BrokenWriter
public BrokenWriter(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
Constructs a new writer that always throws the supplied exception.- Parameters:
exceptionSupplier- a supplier for the IOException or RuntimeException to be thrown.- Since:
- 2.12.0
-
BrokenWriter
public BrokenWriter(java.lang.Throwable exception)
Constructs a new writer that always throws the given exception.- Parameters:
exception- the exception to be thrown.- Since:
- 2.16.0
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionThrows the configured exception.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
flush
public void flush() throws java.io.IOExceptionThrows the configured exception.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionThrows the configured exception.- Specified by:
writein classjava.io.Writer- Parameters:
cbuf- ignored.off- ignored.len- ignored.- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
-