Package org.apache.commons.io.output

# Class ClosedOutputStream

java.lang.Object
java.io.OutputStream
org.apache.commons.io.output.ClosedOutputStream

All Implemented Interfaces:
  `Closeable`, `Flushable`, `AutoCloseable`

public class ClosedOutputStream extends OutputStream
Throws an IOException on all attempts to write to the stream.

Typically uses of this class include testing for corner cases in methods that accept an output stream and acting as a sentinel value instead of a `null` output stream.

Since:
  1.4

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final ClosedOutputStream`
  `CLOSED_OUTPUT_STREAM`
  Deprecated.
  Use `INSTANCE`.
  `static final ClosedOutputStream`
  `INSTANCE`
  The singleton instance.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ClosedOutputStream()`
  Construct a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `flush()`
  Throws an `IOException` to indicate that the stream is closed.
  `void`
  `write(byte[] b, int off, int len)`
  Throws an `IOException` to indicate that the stream is closed.
  `void`
  `write(int b)`
  Throws an `IOException` to indicate that the stream is closed.

  ### Methods inherited from class java.io.OutputStream

  `close, write`

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

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

- ## Field Details

  - ### INSTANCE

    public static final ClosedOutputStream INSTANCE
    The singleton instance.
    Since:
      2.12.0

  - ### CLOSED_OUTPUT_STREAM

    @Deprecated public static final ClosedOutputStream CLOSED_OUTPUT_STREAM
    Deprecated.
    Use `INSTANCE`.
    The singleton instance.

- ## Constructor Details

  - ### ClosedOutputStream

    public ClosedOutputStream()
    Construct a new instance.

- ## Method Details

  - ### flush

    public void flush() throws IOException
    Throws an `IOException` to indicate that the stream is closed.
    Specified by:
      `flush` in interface `Flushable`
    Overrides:
      `flush` in class `OutputStream`
    Throws:
      `IOException` - always thrown

  - ### write

    public void write(byte[] b, int off, int len) throws IOException
    Throws an `IOException` to indicate that the stream is closed.
    Overrides:
      `write` in class `OutputStream`
    Parameters:
      `b` - ignored
      `off` - ignored
      `len` - ignored
    Throws:
      `IOException` - always thrown

  - ### write

    public void write(int b) throws IOException
    Throws an `IOException` to indicate that the stream is closed.
    Specified by:
      `write` in class `OutputStream`
    Parameters:
      `b` - ignored
    Throws:
      `IOException` - always thrown