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
Always throws an exception from all
OutputStream
methods where IOException
is declared.
This class is mostly useful for testing error handling.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionSupplies the exception that is thrown by all methods of this class.static final BrokenOutputStream
The singleton instance using a default IOException. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new stream that always throws anIOException
.BrokenOutputStream
(IOException exception) Deprecated.BrokenOutputStream
(Throwable exception) Constructs a new stream that always throws the given exception.BrokenOutputStream
(Supplier<Throwable> exceptionSupplier) Constructs a new stream that always throws the supplied exception. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Throws the configured exception.void
flush()
Throws the configured exception.private RuntimeException
rethrow()
Throws the configured exception from its supplier.void
write
(int b) Throws the configured exception.Methods inherited from class java.io.OutputStream
write, write
-
Field Details
-
INSTANCE
The singleton instance using a default IOException.- Since:
- 2.12.0
-
exceptionSupplier
Supplies the exception that is thrown by all methods of this class.
-
-
Constructor Details
-
BrokenOutputStream
public BrokenOutputStream()Constructs a new stream that always throws anIOException
. -
BrokenOutputStream
Deprecated.Constructs a new stream that always throws the given exception.- Parameters:
exception
- the exception to be thrown.
-
BrokenOutputStream
Constructs a new stream that always throws the supplied exception.- Parameters:
exceptionSupplier
- a supplier for the IOException or RuntimeException to be thrown.- Since:
- 2.12.0
-
BrokenOutputStream
Constructs a new stream that always throws the given exception.- Parameters:
exception
- the exception to be thrown.- Since:
- 2.16.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 throws the exception configured in a constructor.
-
flush
Throws the configured exception.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- always throws the exception configured in a constructor.
-
rethrow
Throws the configured exception from its supplier.- Returns:
- Throws the configured exception from its supplier.
-
write
Throws the configured exception.- Specified by:
write
in classOutputStream
- Parameters:
b
- ignored.- Throws:
IOException
- always throws the exception configured in a constructor.
-
BrokenOutputStream(Throwable)
.