Class ClosedWriter

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public class ClosedWriter
    extends java.io.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
    • Constructor Summary

      Constructors 
      Constructor Description
      ClosedWriter()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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, nullWriter, write, write, write, write
      • Methods inherited from class java.lang.Object

        equals, 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 java.io.IOException
        Throws an IOException to indicate that the writer is closed.
        Specified by:
        write in class java.io.Writer
        Parameters:
        cbuf - ignored
        off - ignored
        len - ignored
        Throws:
        java.io.IOException - always thrown
      • flush

        public void flush()
                   throws java.io.IOException
        Throws an IOException to indicate that the stream is closed.
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
        Throws:
        java.io.IOException - always thrown
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer
        Throws:
        java.io.IOException