public class BrokenWriter extends Writer
Writer methods where IOException is declared.
This class is mostly useful for testing error handling.
| Modifier and Type | Field and Description |
|---|---|
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.util.function.Supplier<Throwable> exceptionSupplier)
Constructs a new writer that always throws the supplied exception.
|
BrokenWriter(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.
|
void |
write(char[] cbuf,
int off,
int len)
Throws the configured exception.
|
public static final BrokenWriter INSTANCE
public BrokenWriter()
IOException.public BrokenWriter(java.util.function.Supplier<Throwable> exceptionSupplier)
exceptionSupplier - a supplier for the IOException or RuntimeException to be thrown.public BrokenWriter(Throwable exception)
exception - the exception to be thrown.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class WriterIOException - always throws the exception configured in a constructor.public void flush()
throws IOException
flush in interface Flushableflush in class WriterIOException - always throws the exception configured in a constructor.public void write(char[] cbuf,
int off,
int len)
throws IOException
write in class Writercbuf - ignored.off - ignored.len - ignored.IOException - always throws the exception configured in a constructor.