Package org.apache.commons.io.output
Class BrokenOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.io.output.BrokenOutputStream
-
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
public class BrokenOutputStream extends OutputStream
Broken output stream. This stream always throws anIOException
from allOutputStream
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 anIOException
BrokenOutputStream(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
-
-
-
-
Constructor Detail
-
BrokenOutputStream
public BrokenOutputStream(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 anIOException
-
-
Method Detail
-
write
public void write(int b) throws IOException
Throws the configured exception.- Specified by:
write
in classOutputStream
- Parameters:
b
- ignored- Throws:
IOException
- always thrown
-
flush
public void flush() throws IOException
Throws the configured exception.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- always thrown
-
close
public void close() throws IOException
Throws the configured exception.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
- always thrown
-
-