Package org.apache.commons.io.output
Class CloseShieldOutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.apache.commons.io.output.ProxyOutputStream
org.apache.commons.io.output.CloseShieldOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Proxy stream that prevents the underlying output stream from being closed.
This class is typically used in cases where an output stream needs to be passed to a component that wants to explicitly close the stream even if other components would still use the stream for output.
- Since:
- 1.4
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.io.output.ProxyOutputStream
ProxyOutputStream.Builder -
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCloseShieldOutputStream(OutputStream outputStream) Deprecated.Using this constructor prevents IDEs from warning if the underlying output stream is never closed. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Replaces the underlying output stream with aClosedOutputStreamsentinel.static CloseShieldOutputStreamwrap(OutputStream outputStream) Constructs a proxy that shields the given output stream from being closed.Methods inherited from class org.apache.commons.io.output.ProxyOutputStream
afterWrite, beforeWrite, flush, handleIOException, setReference, unwrap, write, write, write, writeRepeat, writeRepeat, writeRepeatMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
CloseShieldOutputStream
Deprecated.Using this constructor prevents IDEs from warning if the underlying output stream is never closed. Usewrap(OutputStream)instead.Constructs a proxy that shields the given output stream from being closed.- Parameters:
outputStream- underlying output stream.
-
-
Method Details
-
wrap
Constructs a proxy that shields the given output stream from being closed.- Parameters:
outputStream- the output stream to wrap.- Returns:
- the created proxy.
- Since:
- 2.9.0
-
close
Replaces the underlying output stream with aClosedOutputStreamsentinel. The original output stream will remain open, but this proxy will appear closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classProxyOutputStream
-