public class BrokenWriter
extends java.io.Writer
IOException from all Writer methods.
This class is mostly useful for testing error handling in code that uses a writer.
| Modifier and Type | Field and Description |
|---|---|
private java.util.function.Supplier<java.io.IOException> |
exceptionSupplier
A supplier for the exception that is thrown by all methods of this class.
|
static BrokenWriter |
INSTANCE
The singleton instance.
|
| Constructor and Description |
|---|
BrokenWriter()
Constructs a new writer that always throws an
IOException. |
BrokenWriter(java.io.IOException exception)
Constructs a new writer that always throws the given exception.
|
BrokenWriter(java.util.function.Supplier<java.io.IOException> exceptionSupplier)
Constructs a new writer that always throws an
IOException. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Throws the configured exception.
|
void |
flush()
Throws the configured exception.
|
void |
write(char[] cbuf,
int off,
int len)
Throws the configured exception.
|
public static final BrokenWriter INSTANCE
private final java.util.function.Supplier<java.io.IOException> exceptionSupplier
public BrokenWriter()
IOException.public BrokenWriter(java.io.IOException exception)
exception - the exception to be thrown.public BrokenWriter(java.util.function.Supplier<java.io.IOException> exceptionSupplier)
IOException.exceptionSupplier - a supplier for 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 thrownpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.Writerjava.io.IOException - always thrownpublic void write(char[] cbuf,
int off,
int len)
throws java.io.IOException
write in class java.io.Writercbuf - ignoredoff - ignoredlen - ignoredjava.io.IOException - always thrown