Package org.apache.commons.io.output
Class ClosedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.commons.io.output.ClosedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class ClosedOutputStream extends java.io.OutputStream
Throws an IOException on all attempts to write to the stream.Typically uses of this class include testing for corner cases in methods that accept an output stream and acting as a sentinel value instead of a
nulloutput stream.- Since:
- 1.4
-
-
Field Summary
Fields Modifier and Type Field Description static ClosedOutputStreamCLOSED_OUTPUT_STREAMDeprecated.UseINSTANCE.static ClosedOutputStreamINSTANCEThe singleton instance.
-
Constructor Summary
Constructors Constructor Description ClosedOutputStream()Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflush()Throws anIOExceptionto indicate that the stream is closed.voidwrite(byte[] b, int off, int len)Throws anIOExceptionto indicate that the stream is closed.voidwrite(int b)Throws anIOExceptionto indicate that the stream is closed.
-
-
-
Field Detail
-
INSTANCE
public static final ClosedOutputStream INSTANCE
The singleton instance.- Since:
- 2.12.0
-
CLOSED_OUTPUT_STREAM
@Deprecated public static final ClosedOutputStream CLOSED_OUTPUT_STREAM
Deprecated.UseINSTANCE.The singleton instance.
-
-
Constructor Detail
-
ClosedOutputStream
public ClosedOutputStream()
Construct a new instance.
-
-
Method Detail
-
flush
public void flush() throws java.io.IOException
Throws anIOExceptionto indicate that the stream is closed.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException- always thrown
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException
Throws anIOExceptionto indicate that the stream is closed.- Overrides:
writein classjava.io.OutputStream- Parameters:
b- Byte array, nevernull.off- The start offset in the byte array.len- The number of bytes to write.- Throws:
java.lang.NullPointerException- if the byte array isnull.java.lang.IndexOutOfBoundsException- ifofforlenare negative, or ifoff + lenis greater thanb.length.java.io.IOException- always thrown.
-
write
public void write(int b) throws java.io.IOException
Throws anIOExceptionto indicate that the stream is closed.- Specified by:
writein classjava.io.OutputStream- Parameters:
b- ignored.- Throws:
java.io.IOException- always thrown.
-
-