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 TypeFieldDescriptionstatic final BrokenOutputStreamThe 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
Methods inherited from class java.io.OutputStream
write, write
-
Field Details
-
INSTANCE
The singleton instance using a default IOException.- Since:
- 2.12.0
-
-
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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- always throws the exception configured in a constructor.
-
flush
Throws the configured exception.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- always throws the exception configured in a constructor.
-
write
Throws the configured exception.- Specified by:
writein classOutputStream- Parameters:
b- ignored.- Throws:
IOException- always throws the exception configured in a constructor.
-
BrokenOutputStream(Throwable).