Package org.apache.commons.io.input
Class BrokenReader
java.lang.Object
java.io.Reader
org.apache.commons.io.input.BrokenReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Readable
Always throws an exception from all
Reader
methods where IOException
is declared.
This class is mostly useful for testing error handling.
- Since:
- 2.7
-
Field Summary
Modifier and TypeFieldDescriptionstatic final BrokenReader
A singleton instance using a default IOException. -
Constructor Summary
ConstructorDescriptionConstructs a new reader that always throws anIOException
.BrokenReader
(IOException exception) Deprecated.BrokenReader
(Throwable exception) Constructs a new reader that always throws the given exception.BrokenReader
(Supplier<Throwable> exceptionSupplier) Constructs a new reader that always throws the supplied exception. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Throws the configured exception.void
mark
(int readAheadLimit) Throws the configured exception.int
read
(char[] cbuf, int off, int len) Throws the configured exception.boolean
ready()
Throws the configured exception.void
reset()
Throws the configured exception.long
skip
(long n) Throws the configured exception.Methods inherited from class java.io.Reader
markSupported, read, read, read
-
Field Details
-
INSTANCE
A singleton instance using a default IOException.- Since:
- 2.12.0
-
-
Constructor Details
-
BrokenReader
public BrokenReader()Constructs a new reader that always throws anIOException
. -
BrokenReader
Deprecated.Constructs a new reader that always throws the given exception.- Parameters:
exception
- the exception to be thrown.
-
BrokenReader
Constructs a new reader that always throws the supplied exception.- Parameters:
exceptionSupplier
- a supplier for the IOException or RuntimeException to be thrown.- Since:
- 2.12.0
-
BrokenReader
Constructs a new reader 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
- Specified by:
close
in classReader
- Throws:
IOException
- always throws the exception configured in a constructor.
-
mark
Throws the configured exception.- Overrides:
mark
in classReader
- Parameters:
readAheadLimit
- ignored.- Throws:
IOException
- always throws the exception configured in a constructor.
-
read
Throws the configured exception.- Specified by:
read
in classReader
- Parameters:
cbuf
- ignored.off
- ignored.len
- ignored.- Returns:
- nothing.
- Throws:
IOException
- always throws the exception configured in a constructor.
-
ready
Throws the configured exception.- Overrides:
ready
in classReader
- Returns:
- nothing.
- Throws:
IOException
- always throws the exception configured in a constructor.
-
reset
Throws the configured exception.- Overrides:
reset
in classReader
- Throws:
IOException
- always throws the exception configured in a constructor.
-
skip
Throws the configured exception.- Overrides:
skip
in classReader
- Parameters:
n
- ignored.- Returns:
- nothing.
- Throws:
IOException
- always throws the exception configured in a constructor.
-
BrokenReader(Throwable)
.