Package org.apache.commons.io.output
Class CloseShieldWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.FilterWriter
-
- org.apache.commons.io.output.ProxyWriter
-
- org.apache.commons.io.output.CloseShieldWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class CloseShieldWriter extends ProxyWriter
Proxy writer that prevents the underlying writer from being closed.This class is typically used in cases where a writer needs to be passed to a component that wants to explicitly close the writer even if other components would still use the writer for output.
- Since:
- 2.7
-
-
Constructor Summary
Constructors Constructor Description CloseShieldWriter(java.io.Writer writer)
Deprecated.Using this constructor prevents IDEs from warning if the underlying writer is never closed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Replaces the underlying writer with aClosedWriter
sentinel.static CloseShieldWriter
wrap(java.io.Writer writer)
Creates a proxy that shields the given writer from being closed.
-
-
-
Constructor Detail
-
CloseShieldWriter
@Deprecated public CloseShieldWriter(java.io.Writer writer)
Deprecated.Using this constructor prevents IDEs from warning if the underlying writer is never closed. Usewrap(Writer)
instead.Creates a proxy that shields the given writer from being closed.- Parameters:
writer
- underlying writer
-
-
Method Detail
-
wrap
public static CloseShieldWriter wrap(java.io.Writer writer)
Creates a proxy that shields the given writer from being closed.- Parameters:
writer
- the writer to wrap- Returns:
- the created proxy
- Since:
- 2.9.0
-
close
public void close()
Replaces the underlying writer with aClosedWriter
sentinel. The original writer 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 classProxyWriter
-
-