public class BrokenOutputStream extends OutputStream
OutputStream methods where IOException is declared.
This class is mostly useful for testing error handling.
| Modifier and Type | Field and Description |
|---|---|
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.util.function.Function<String,Throwable> exceptionFunction)
Constructs a new stream that always throws the supplied exception.
|
BrokenOutputStream(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.
|
void |
write(int b)
Throws the configured exception.
|
write, writepublic static final BrokenOutputStream INSTANCE
public BrokenOutputStream()
IOException.public BrokenOutputStream(java.util.function.Function<String,Throwable> exceptionFunction)
This class uses the invoked method name as the function input.
exceptionFunction - a supplier for the IOException or RuntimeException to be thrown.public BrokenOutputStream(Throwable exception)
exception - the exception to be thrown.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - always throws the exception configured in a constructor.public void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOException - always throws the exception configured in a constructor.public void write(int b)
throws IOException
write in class OutputStreamb - ignored.IOException - always throws the exception configured in a constructor.