Class CloseShieldInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.commons.io.input.ProxyInputStream
org.apache.commons.io.input.CloseShieldInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
Proxy stream that prevents the underlying input stream from being closed.
This class is typically used in cases where an input stream needs to be passed to a component that wants to explicitly close the stream even if more input would still be available to other components.
- Since:
- 1.4
-
Nested Class Summary
Nested classes/interfaces inherited from class ProxyInputStream
ProxyInputStream.AbstractBuilder<T,B> -
Field Summary
Fields inherited from class FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionCloseShieldInputStream(InputStream inputStream) Deprecated.Using this constructor prevents IDEs from warning if the underlying input stream is never closed. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Replaces the underlying input stream with aClosedInputStreamsentinel.static InputStreamsystemIn(InputStream inputStream) Constructs a proxy that only shieldsSystem.infrom closing.static CloseShieldInputStreamwrap(InputStream inputStream) Constructs a proxy that shields the given input stream from being closed.Methods inherited from class ProxyInputStream
afterRead, available, beforeRead, handleIOException, mark, markSupported, read, read, read, reset, setReference, skip, unwrapMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
CloseShieldInputStream
Deprecated.Using this constructor prevents IDEs from warning if the underlying input stream is never closed. Usewrap(InputStream)instead.Constructs a proxy that shields the given input stream from being closed.- Parameters:
inputStream- underlying input stream
-
-
Method Details
-
systemIn
-
wrap
Constructs a proxy that shields the given input stream from being closed.- Parameters:
inputStream- the input stream to wrap- Returns:
- the created proxy
- Since:
- 2.9.0
-
close
Replaces the underlying input stream with aClosedInputStreamsentinel. The original input stream will remain open, but this proxy will appear closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classProxyInputStream
-