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 exception 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` A singleton.

    - ### 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

    - #### CLOSED_WRITER

          public static final ClosedWriter CLOSED_WRITER

      A singleton.

  - ### Constructor Detail

    - #### ClosedWriter

          public ClosedWriter()

  - ### Method Detail

    - #### 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

    - #### 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

    - #### 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`

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