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
Modifier and TypeFieldDescriptionstatic final BrokenOutputStream
The singleton instance using a default IOException. -
Constructor Summary
ConstructorDescriptionConstructs 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:
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.
-
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)
.