Package org.apache.commons.io.output
Class BrokenOutputStream
java.lang.Object
java.io.OutputStream
org.apache.commons.io.output.BrokenOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Broken output stream. This stream always throws an
IOException
from
all OutputStream
methods.
This class is mostly useful for testing error handling in code that uses an output stream.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Supplier
<IOException> A supplier for the exception that is thrown by all methods of this class.static final BrokenOutputStream
A singleton instance. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new stream that always throws anIOException
.BrokenOutputStream
(IOException exception) Creates a new stream that always throws the given exception.BrokenOutputStream
(Supplier<IOException> exceptionSupplier) Creates a new stream that always throws anIOException
. -
Method Summary
Methods inherited from class java.io.OutputStream
write, write
-
Field Details
-
INSTANCE
A singleton instance.- Since:
- 2.12.0
-
exceptionSupplier
A supplier for the exception that is thrown by all methods of this class.
-
-
Constructor Details
-
BrokenOutputStream
public BrokenOutputStream()Creates a new stream that always throws anIOException
. -
BrokenOutputStream
Creates a new stream that always throws the given exception.- Parameters:
exception
- the exception to be thrown.
-
BrokenOutputStream
Creates a new stream that always throws anIOException
.- Parameters:
exceptionSupplier
- a supplier for the exception to be thrown.- Since:
- 2.12.0
-
-
Method Details
-
close
Throws the configured exception.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- always thrown
-
flush
Throws the configured exception.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- always thrown
-
write
Throws the configured exception.- Specified by:
write
in classOutputStream
- Parameters:
b
- ignored- Throws:
IOException
- always thrown
-