Class BrokenOutputStream

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

    public class BrokenOutputStream
    extends java.io.OutputStream
    Always throws an exception from all OutputStream methods where IOException is declared.

    This class is mostly useful for testing error handling.

    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static BrokenOutputStream INSTANCE
      The singleton instance using a default IOException.
    • Constructor Summary

      Constructors 
      Constructor Description
      BrokenOutputStream()
      Constructs a new stream that always throws an IOException.
      BrokenOutputStream​(java.io.IOException exception)
      BrokenOutputStream​(java.lang.Throwable exception)
      Constructs a new stream that always throws the given exception.
      BrokenOutputStream​(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
      Constructs a new stream that always throws the supplied 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

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE

        public static final BrokenOutputStream INSTANCE
        The singleton instance using a default IOException.
        Since:
        2.12.0
    • Constructor Detail

      • BrokenOutputStream

        public BrokenOutputStream()
        Constructs a new stream that always throws an IOException.
      • BrokenOutputStream

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

        public BrokenOutputStream​(java.util.function.Supplier<java.lang.Throwable> exceptionSupplier)
        Constructs a new stream that always throws the supplied exception.
        Parameters:
        exceptionSupplier - a supplier for the IOException or RuntimeException to be thrown.
        Since:
        2.12.0
      • BrokenOutputStream

        public BrokenOutputStream​(java.lang.Throwable exception)
        Constructs a new stream that always throws the given exception.
        Parameters:
        exception - the exception to be thrown.
        Since:
        2.16.0
    • Method Detail

      • 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 throws the exception configured in a constructor.
      • 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 throws the exception configured in a constructor.
      • 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 throws the exception configured in a constructor.