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:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class CloseShieldOutputStream extends ProxyOutputStream
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
-
-
Constructor Summary
Constructors Constructor Description CloseShieldOutputStream(java.io.OutputStream outputStream)
Deprecated.Using this constructor prevents IDEs from warning if the underlying output stream is never closed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Replaces the underlying output stream with aClosedOutputStream
sentinel.static CloseShieldOutputStream
wrap(java.io.OutputStream outputStream)
Creates a proxy that shields the given output stream from being closed.-
Methods inherited from class org.apache.commons.io.output.ProxyOutputStream
flush, write, write, write
-
-
-
-
Constructor Detail
-
CloseShieldOutputStream
@Deprecated public CloseShieldOutputStream(java.io.OutputStream outputStream)
Deprecated.Using this constructor prevents IDEs from warning if the underlying output stream is never closed. Usewrap(OutputStream)
instead.Creates a proxy that shields the given output stream from being closed.- Parameters:
outputStream
- underlying output stream
-
-
Method Detail
-
wrap
public static CloseShieldOutputStream wrap(java.io.OutputStream outputStream)
Creates 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
public void close()
Replaces the underlying output stream with aClosedOutputStream
sentinel. The original output stream will remain open, but this proxy will appear closed.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classProxyOutputStream
-
-