Package org.apache.commons.io.input
Class BrokenInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.BrokenInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Always throws an exception from all
InputStream
methods where IOException
is declared.
This class is mostly useful for testing error handling.
- Since:
- 2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionA supplier for the exception that is thrown by all methods of this class.static final BrokenInputStream
The singleton instance using a default IOException. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new stream that always throws anIOException
.BrokenInputStream
(IOException exception) Deprecated.BrokenInputStream
(Throwable exception) Constructs a new stream that always throws the given exception.BrokenInputStream
(Supplier<Throwable> exceptionSupplier) Constructs a new stream that always throws the supplied exception. -
Method Summary
Modifier and TypeMethodDescriptionint
Throws the configured exception.void
close()
Throws the configured exception.int
read()
Throws the configured exception.void
reset()
Throws the configured exception.private RuntimeException
rethrow()
Throws the configured exception from its supplier.long
skip
(long n) Throws the configured exception.Methods inherited from class java.io.InputStream
mark, markSupported, read, read
-
Field Details
-
INSTANCE
The singleton instance using a default IOException.- Since:
- 2.12.0
-
exceptionSupplier
A supplier for the exception that is thrown by all methods of this class.
-
-
Constructor Details
-
BrokenInputStream
public BrokenInputStream()Constructs a new stream that always throws anIOException
. -
BrokenInputStream
Deprecated.Constructs a new stream that always throws the given exception.- Parameters:
exception
- the exception to be thrown.
-
BrokenInputStream
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
-
BrokenInputStream
Constructs a new stream that always throws the given exception.- Parameters:
exception
- the exception to be thrown.- Since:
- 2.16.0
-
-
Method Details
-
available
Throws the configured exception.- Overrides:
available
in classInputStream
- Returns:
- nothing.
- Throws:
IOException
- always throws the exception configured in a constructor.
-
close
Throws the configured exception.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- always throws the exception configured in a constructor.
-
read
Throws the configured exception.- Specified by:
read
in classInputStream
- Returns:
- nothing.
- Throws:
IOException
- always throws the exception configured in a constructor.
-
reset
Throws the configured exception.- Overrides:
reset
in classInputStream
- 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.
-
skip
Throws the configured exception.- Overrides:
skip
in classInputStream
- Parameters:
n
- ignored.- Returns:
- nothing.
- Throws:
IOException
- always throws the exception configured in a constructor.
-
BrokenInputStream(Throwable)
.