Package org.apache.commons.io.input
Class CloseShieldReader
- java.lang.Object
-
- java.io.Reader
-
- java.io.FilterReader
-
- org.apache.commons.io.input.ProxyReader
-
- org.apache.commons.io.input.CloseShieldReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Readable
public class CloseShieldReader extends ProxyReader
Proxy reader that prevents the underlying reader from being closed.This class is typically used in cases where a reader needs to be passed to a component that wants to explicitly close the reader even if more input would still be available to other components.
- Since:
- 2.7
-
-
Constructor Summary
Constructors Constructor Description CloseShieldReader(java.io.Reader reader)Deprecated.Using this constructor prevents IDEs from warning if the underlying reader is never closed.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Replaces the underlying reader with aClosedReadersentinel.static CloseShieldReaderwrap(java.io.Reader reader)Creates a proxy that shields the given reader from being closed.-
Methods inherited from class org.apache.commons.io.input.ProxyReader
mark, markSupported, read, read, read, read, ready, reset, skip
-
-
-
-
Constructor Detail
-
CloseShieldReader
@Deprecated public CloseShieldReader(java.io.Reader reader)
Deprecated.Using this constructor prevents IDEs from warning if the underlying reader is never closed. Usewrap(Reader)instead.Creates a proxy that shields the given reader from being closed.- Parameters:
reader- underlying reader
-
-
Method Detail
-
wrap
public static CloseShieldReader wrap(java.io.Reader reader)
Creates a proxy that shields the given reader from being closed.- Parameters:
reader- the reader to wrap- Returns:
- the created proxy
- Since:
- 2.9.0
-
close
public void close()
Replaces the underlying reader with aClosedReadersentinel. The original reader will remain open, but this proxy will appear closed.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classProxyReader
-
-