public class BrokenOutputStream
extends java.io.OutputStream
OutputStream 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 BrokenOutputStream |
INSTANCE
The singleton instance using a default IOException.
|
| Constructor and Description |
|---|
BrokenOutputStream()
Constructs a new stream that always throws an
IOException. |
BrokenOutputStream(java.io.IOException exception)
Deprecated.
|
BrokenOutputStream(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
Constructs a new stream that always throws the supplied exception.
|
BrokenOutputStream(java.lang.Throwable exception)
Constructs a new stream 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(int b)
Throws the configured exception.
|
public static final BrokenOutputStream INSTANCE
private final java.util.function.Supplier<java.lang.Throwable> exceptionSupplier
public BrokenOutputStream()
IOException.@Deprecated public BrokenOutputStream(java.io.IOException exception)
BrokenOutputStream(Throwable).exception - the exception to be thrown.public BrokenOutputStream(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
exceptionSupplier - a supplier for the IOException or RuntimeException to be thrown.public BrokenOutputStream(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.OutputStreamjava.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.OutputStreamjava.io.IOException - always throws the exception configured in a constructor.private java.lang.RuntimeException rethrow()
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - ignored.java.io.IOException - always throws the exception configured in a constructor.