public class BrokenWriter
extends java.io.Writer
Writer methods where IOException is declared.
This class is mostly useful for testing error handling.
| Modifier and Type | Field and Description |
|---|---|
private java.util.function.Supplier<java.lang.Throwable> |
exceptionSupplier
Supplies the exception that is thrown by all methods of this class.
|
static BrokenWriter |
INSTANCE
The singleton instance using a default IOException.
|
| Constructor and Description |
|---|
BrokenWriter()
Constructs a new writer that always throws an
IOException. |
BrokenWriter(java.io.IOException exception)
Deprecated.
|
BrokenWriter(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
Constructs a new writer that always throws the supplied exception.
|
BrokenWriter(java.lang.Throwable exception)
Constructs a new writer that always throws the given exception.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Throws the configured exception.
|
void |
flush()
Throws the configured exception.
|
private java.lang.RuntimeException |
rethrow()
Throws the configured exception from its supplier.
|
void |
write(char[] cbuf,
int off,
int len)
Throws the configured exception.
|
public static final BrokenWriter INSTANCE
private final java.util.function.Supplier<java.lang.Throwable> exceptionSupplier
public BrokenWriter()
IOException.@Deprecated public BrokenWriter(java.io.IOException exception)
BrokenWriter(Throwable).exception - the exception to be thrown.public BrokenWriter(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
exceptionSupplier - a supplier for the IOException or RuntimeException to be thrown.public BrokenWriter(java.lang.Throwable exception)
exception - the exception to be thrown.public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Writerjava.io.IOException - always throws the exception configured in a constructor.public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOException - always throws the exception configured in a constructor.private java.lang.RuntimeException rethrow()
public void write(char[] cbuf,
int off,
int len)
throws java.io.IOException
write in class java.io.Writercbuf - ignored.off - ignored.len - ignored.java.io.IOException - always throws the exception configured in a constructor.