org.apache.commons.io.input
Class BrokenInputStream
- java.lang.Object
-
- java.io.InputStream
-
- org.apache.commons.io.input.BrokenInputStream
-
- All Implemented Interfaces:
- Closeable, AutoCloseable
public class BrokenInputStream extends InputStream
Broken input stream. This stream always throws anIOException
from all theInputStream
methods where the exception is declared.This class is mostly useful for testing error handling in code that uses an input stream.
- Since:
- 2.0
-
Constructor Summary
Constructors Constructor and Description BrokenInputStream()
Creates a new stream that always throws anIOException
BrokenInputStream(IOException exception)
Creates a new stream that always throws the given exception.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description int
available()
Throws the configured exception.void
close()
Throws the configured exception.int
read()
Throws the configured exception.void
reset()
Throws the configured exception.long
skip(long n)
Throws the configured exception.Methods inherited from class java.io.InputStream
mark, markSupported, read, read
-
Constructor Detail
BrokenInputStream
public BrokenInputStream(IOException exception)
Creates a new stream that always throws the given exception.- Parameters:
-
exception
- the exception to be thrown
BrokenInputStream
public BrokenInputStream()
Creates a new stream that always throws anIOException
Method Detail
read
public int read() throws IOException
Throws the configured exception.- Specified by:
-
read
in classInputStream
- Returns:
- nothing
- Throws:
-
IOException
- always thrown
available
public int available() throws IOException
Throws the configured exception.- Overrides:
-
available
in classInputStream
- Returns:
- nothing
- Throws:
-
IOException
- always thrown
skip
public long skip(long n) throws IOException
Throws the configured exception.- Overrides:
-
skip
in classInputStream
- Parameters:
-
n
- ignored - Returns:
- nothing
- Throws:
-
IOException
- always thrown
reset
public void reset() throws IOException
Throws the configured exception.- Overrides:
-
reset
in classInputStream
- Throws:
-
IOException
- always thrown
close
public void close() throws IOException
Throws the configured exception.- Specified by:
-
close
in interfaceCloseable
- Specified by:
-
close
in interfaceAutoCloseable
- Overrides:
-
close
in classInputStream
- Throws:
-
IOException
- always thrown
Copyright © 2002–2021 The Apache Software Foundation. All rights reserved.