org.apache.commons.io.output

## Class BrokenWriter

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

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

      public class BrokenWriter
      extends Writer

  Broken writer. This writer always throws an `IOException` from all `Writer` methods.

  This class is mostly useful for testing error handling in code that uses a writer.

  Since:
    2.0

- - ### Field Summary

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

      `lock`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BrokenWriter()` Creates a new writer that always throws an `IOException`
    `BrokenWriter(IOException exception)` Creates a new writer that always throws the given exception.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Throws the configured exception.
    `void` | `flush()` Throws the configured exception.
    `void` | `write(char[] cbuf, int off, int len)` Throws the configured exception.

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

- - ### Constructor Detail

    - #### BrokenWriter

          public BrokenWriter(IOException exception)

      Creates a new writer that always throws the given exception.
      Parameters:
        `exception` - the exception to be thrown

    - #### BrokenWriter

          public BrokenWriter()

      Creates a new writer that always throws an `IOException`

  - ### Method Detail

    - #### write

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

      Throws the configured exception.
      Specified by:
        `write` in class `Writer`
      Parameters:
        `cbuf` - ignored
        `off` - ignored
        `len` - ignored
      Throws:
        `IOException` - always thrown

    - #### flush

          public void flush()
                     throws IOException

      Throws the configured exception.
      Specified by:
        `flush` in interface `Flushable`
      Specified by:
        `flush` in class `Writer`
      Throws:
        `IOException` - always thrown

    - #### close

          public void close()
                     throws IOException

      Throws the configured exception.
      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Specified by:
        `close` in class `Writer`
      Throws:
        `IOException` - always thrown

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