Package org.apache.commons.io.input
Class BrokenInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.BrokenInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class BrokenInputStream extends java.io.InputStreamAlways throws an exception from allInputStreammethods whereIOExceptionis declared.This class is mostly useful for testing error handling.
- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.function.Supplier<java.lang.Throwable>exceptionSupplierA supplier for the exception that is thrown by all methods of this class.static BrokenInputStreamINSTANCEThe singleton instance using a default IOException.
-
Constructor Summary
Constructors Constructor Description BrokenInputStream()Constructs a new stream that always throws anIOException.BrokenInputStream(java.io.IOException exception)Deprecated.BrokenInputStream(java.lang.Throwable exception)Constructs a new stream that always throws the given exception.BrokenInputStream(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)Constructs a new stream that always throws the supplied exception.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Throws the configured exception.voidclose()Throws the configured exception.(package private) java.lang.ThrowablegetThrowable()Gets the Throwable to throw.intread()Throws the configured exception.voidreset()Throws the configured exception.private java.lang.RuntimeExceptionrethrow()Throws the configured exception from its supplier.longskip(long n)Throws the configured exception.
-
-
-
Field Detail
-
INSTANCE
public static final BrokenInputStream INSTANCE
The singleton instance using a default IOException.- Since:
- 2.12.0
-
exceptionSupplier
private final java.util.function.Supplier<java.lang.Throwable> exceptionSupplier
A supplier for the exception that is thrown by all methods of this class.
-
-
Constructor Detail
-
BrokenInputStream
public BrokenInputStream()
Constructs a new stream that always throws anIOException.
-
BrokenInputStream
@Deprecated public BrokenInputStream(java.io.IOException exception)
Deprecated.Constructs a new stream that always throws the given exception.- Parameters:
exception- the exception to be thrown.
-
BrokenInputStream
public BrokenInputStream(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
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
public BrokenInputStream(java.lang.Throwable exception)
Constructs a new stream that always throws the given exception.- Parameters:
exception- the exception to be thrown.- Since:
- 2.16.0
-
-
Method Detail
-
available
public int available() throws java.io.IOExceptionThrows the configured exception.- Overrides:
availablein classjava.io.InputStream- Returns:
- nothing.
- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
close
public void close() throws java.io.IOExceptionThrows the configured exception.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.InputStream- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
getThrowable
java.lang.Throwable getThrowable()
Gets the Throwable to throw. Package-private for testing.- Returns:
- the Throwable to throw.
-
read
public int read() throws java.io.IOExceptionThrows the configured exception.- Specified by:
readin classjava.io.InputStream- Returns:
- nothing.
- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
reset
public void reset() throws java.io.IOExceptionThrows the configured exception.- Overrides:
resetin classjava.io.InputStream- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
rethrow
private java.lang.RuntimeException rethrow()
Throws the configured exception from its supplier.- Returns:
- Throws the configured exception from its supplier.
-
skip
public long skip(long n) throws java.io.IOExceptionThrows the configured exception.- Overrides:
skipin classjava.io.InputStream- Parameters:
n- ignored.- Returns:
- nothing.
- Throws:
java.io.IOException- always throws the exception configured in a constructor.
-
-