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`

public class BrokenInputStream extends InputStream
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

  Fields
  Modifier and Type
  Field
  Description
  `static final BrokenInputStream`
  `INSTANCE`
  The singleton instance using a default IOException.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BrokenInputStream()`
  Constructs a new stream that always throws an `IOException`.
  `BrokenInputStream(IOException exception)`
  Deprecated.
  Use `BrokenInputStream(Throwable)`.
  `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 Type
  Method
  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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### INSTANCE

    public static final BrokenInputStream INSTANCE
    The singleton instance using a default IOException.
    Since:
      2.12.0

- ## Constructor Details

  - ### BrokenInputStream

    public BrokenInputStream()
    Constructs a new stream that always throws an `IOException`.

  - ### BrokenInputStream

    @Deprecated public BrokenInputStream(IOException exception)
    Deprecated.
    Use `BrokenInputStream(Throwable)`.
    Constructs a new stream that always throws the given exception.
    Parameters:
      `exception` - the exception to be thrown.

  - ### BrokenInputStream

    public BrokenInputStream(Supplier<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(Throwable exception)
    Constructs a new stream that always throws the given exception.
    Parameters:
      `exception` - the exception to be thrown.
    Since:
      2.16.0

- ## Method Details

  - ### available

    public int available() throws IOException
    Throws the configured exception.
    Overrides:
      `available` in class `InputStream`
    Returns:
      nothing.
    Throws:
      `IOException` - always throws the exception configured in a constructor.

  - ### close

    public void close() throws IOException
    Throws the configured exception.
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `InputStream`
    Throws:
      `IOException` - always throws the exception configured in a constructor.

  - ### read

    public int read() throws IOException
    Throws the configured exception.
    Specified by:
      `read` in class `InputStream`
    Returns:
      nothing.
    Throws:
      `IOException` - always throws the exception configured in a constructor.

  - ### reset

    public void reset() throws IOException
    Throws the configured exception.
    Overrides:
      `reset` in class `InputStream`
    Throws:
      `IOException` - always throws the exception configured in a constructor.

  - ### skip

    public long skip(long n) throws IOException
    Throws the configured exception.
    Overrides:
      `skip` in class `InputStream`
    Parameters:
      `n` - ignored.
    Returns:
      nothing.
    Throws:
      `IOException` - always throws the exception configured in a constructor.