Package org.apache.commons.io.output
Class BrokenWriter
java.lang.Object
java.io.Writer
org.apache.commons.io.output.BrokenWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Always throws an
IOException
from all Writer
methods.
This class is mostly useful for testing error handling in code that uses a writer.
- 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 BrokenWriter
The singleton instance. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new writer that always throws anIOException
.BrokenWriter
(IOException exception) Creates a new writer that always throws the given exception.BrokenWriter
(Supplier<IOException> exceptionSupplier) Creates a new writer that always throws anIOException
. -
Method Summary
-
Field Details
-
INSTANCE
The singleton instance.- Since:
- 2.12.0
-
exceptionSupplier
A supplier for the exception that is thrown by all methods of this class.
-
-
Constructor Details
-
BrokenWriter
public BrokenWriter()Creates a new writer that always throws anIOException
. -
BrokenWriter
Creates a new writer that always throws the given exception.- Parameters:
exception
- the exception to be thrown.
-
BrokenWriter
Creates a new writer 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
- Specified by:
close
in classWriter
- Throws:
IOException
- always thrown
-
flush
Throws the configured exception.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
- always thrown
-
write
Throws the configured exception.- Specified by:
write
in classWriter
- Parameters:
cbuf
- ignoredoff
- ignoredlen
- ignored- Throws:
IOException
- always thrown
-