org.apache.commons.io.output

## Class ClosedWriter

- java.lang.Object
- - java.io.Writer
  - - org.apache.commons.io.output.ClosedWriter

- All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable

      public class ClosedWriter
      extends Writer

  Throws an IOException on all attempts to write with `close()` implemented as a noop.

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

  Since:
    2.7

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static ClosedWriter` | `CLOSED_WRITER` Deprecated. Use `INSTANCE`.
    `static ClosedWriter` | `INSTANCE` The singleton instance.

    - ### Fields inherited from class java.io.Writer

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ClosedWriter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `void` | `flush()` Throws an `IOException` to indicate that the stream is closed.
    `void` | `write(char[] cbuf, int off, int len)` Throws an `IOException` to indicate that the writer is closed.

    - ### Methods inherited from class java.io.Writer

      `append, append, append, write, write, write, write`

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

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

- - ### Field Detail

    - #### INSTANCE

          public static final ClosedWriter INSTANCE

      The singleton instance.
      Since:
        2.12.0

    - #### CLOSED_WRITER

          @Deprecated
          public static final ClosedWriter CLOSED_WRITER

      Deprecated. Use `INSTANCE`.
      The singleton instance.

  - ### Constructor Detail

    - #### ClosedWriter

          public ClosedWriter()

  - ### Method Detail

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in class `Writer`
      Throws:
        `IOException`

    - #### flush

          public void flush()
                     throws IOException

      Throws an `IOException` to indicate that the stream is closed.
      Specified by:
        `flush` in interface `Flushable`
      Specified by:
        `flush` in class `Writer`
      Throws:
        `IOException` - always thrown

    - #### write

          public void write(char[] cbuf,
                            int off,
                            int len)
                     throws IOException

      Throws an `IOException` to indicate that the writer is closed.
      Specified by:
        `write` in class `Writer`
      Parameters:
        `cbuf` - ignored
        `off` - ignored
        `len` - ignored
      Throws:
        `IOException` - always thrown

Copyright © 2002–2023 The Apache Software Foundation. All rights reserved.