Package org.apache.commons.io.input
Class BrokenReader
- java.lang.Object
-
- java.io.Reader
-
- org.apache.commons.io.input.BrokenReader
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.lang.Readable
public class BrokenReader extends java.io.Reader
Always throws anIOException
from all theReader
methods where the exception is declared.This class is mostly useful for testing error handling.
- Since:
- 2.7
-
-
Field Summary
Fields Modifier and Type Field Description static BrokenReader
INSTANCE
A singleton instance using a default IOException.
-
Constructor Summary
Constructors Constructor Description BrokenReader()
Creates a new reader that always throws anIOException
.BrokenReader(java.io.IOException exception)
Creates a new reader that always throws the given exception.BrokenReader(java.util.function.Supplier<java.io.IOException> exceptionSupplier)
Creates a new reader that always throws anIOException
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.
-
-
-
Field Detail
-
INSTANCE
public static final BrokenReader INSTANCE
A singleton instance using a default IOException.- Since:
- 2.12.0
-
-
Constructor Detail
-
BrokenReader
public BrokenReader()
Creates a new reader that always throws anIOException
.
-
BrokenReader
public BrokenReader(java.io.IOException exception)
Creates a new reader that always throws the given exception.- Parameters:
exception
- the exception to be thrown.
-
BrokenReader
public BrokenReader(java.util.function.Supplier<java.io.IOException> exceptionSupplier)
Creates a new reader that always throws anIOException
- Parameters:
exceptionSupplier
- a supplier for the exception to be thrown.- Since:
- 2.12.0
-
-
Method Detail
-
close
public void close() throws java.io.IOException
Throws the configured exception.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Reader
- Throws:
java.io.IOException
- always thrown
-
mark
public void mark(int readAheadLimit) throws java.io.IOException
Throws the configured exception.- Overrides:
mark
in classjava.io.Reader
- Parameters:
readAheadLimit
- ignored- Throws:
java.io.IOException
- always thrown
-
read
public int read(char[] cbuf, int off, int len) throws java.io.IOException
Throws the configured exception.- Specified by:
read
in classjava.io.Reader
- Parameters:
cbuf
- ignoredoff
- ignoredlen
- ignored- Returns:
- nothing
- Throws:
java.io.IOException
- always thrown
-
ready
public boolean ready() throws java.io.IOException
Throws the configured exception.- Overrides:
ready
in classjava.io.Reader
- Returns:
- nothing
- Throws:
java.io.IOException
- always thrown
-
reset
public void reset() throws java.io.IOException
Throws the configured exception.- Overrides:
reset
in classjava.io.Reader
- Throws:
java.io.IOException
- always thrown
-
skip
public long skip(long n) throws java.io.IOException
Throws the configured exception.- Overrides:
skip
in classjava.io.Reader
- Parameters:
n
- ignored- Returns:
- nothing
- Throws:
java.io.IOException
- always thrown
-
-