Class BrokenOutputStream

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

    public class BrokenOutputStream
    extends java.io.OutputStream
    Broken output stream. This stream always throws an IOException from all OutputStream methods.

    This class is mostly useful for testing error handling in code that uses an output stream.

    Since:
    2.0
    • Constructor Summary

      Constructors 
      Constructor Description
      BrokenOutputStream()
      Creates a new stream that always throws an IOException
      BrokenOutputStream​(java.io.IOException exception)
      Creates a new stream that always throws the given exception.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Throws the configured exception.
      void flush()
      Throws the configured exception.
      void write​(int b)
      Throws the configured exception.
      • Methods inherited from class java.io.OutputStream

        nullOutputStream, write, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BrokenOutputStream

        public BrokenOutputStream​(java.io.IOException exception)
        Creates a new stream that always throws the given exception.
        Parameters:
        exception - the exception to be thrown
      • BrokenOutputStream

        public BrokenOutputStream()
        Creates a new stream that always throws an IOException
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Throws the configured exception.
        Specified by:
        write in class java.io.OutputStream
        Parameters:
        b - ignored
        Throws:
        java.io.IOException - always thrown
      • flush

        public void flush()
                   throws java.io.IOException
        Throws the configured exception.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException - always thrown
      • close

        public void close()
                   throws java.io.IOException
        Throws the configured exception.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException - always thrown