Package org.apache.commons.io.input

# 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`

public class CloseShieldInputStream extends ProxyInputStream
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
  Modifier and Type
  Class
  Description
  `static class`
  `CloseShieldInputStream.Builder`
  Constructs a new builder for `CloseShieldInputStream`.

  ## Nested classes/interfaces inherited from class org.apache.commons.io.input.ProxyInputStream

  `ProxyInputStream.AbstractBuilder<T,B extends AbstractStreamBuilder<T,B>>`

- ## Field Summary

  ### Fields inherited from class java.io.FilterInputStream

  `in`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CloseShieldInputStream(InputStream inputStream)`
  Deprecated.
  Using this constructor prevents IDEs from warning if the underlying input stream is never closed.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static CloseShieldInputStream.Builder`
  `builder()`
  Constructs a new builder for `CloseShieldInputStream`.
  `void`
  `close()`
  Applies the `onClose` function to the underlying input stream, replacing it with the result.
  `static InputStream`
  `systemIn(InputStream inputStream)`
  Constructs a proxy that only shields `System.in` from closing.
  `static CloseShieldInputStream`
  `wrap(InputStream inputStream)`
  Constructs a proxy that shields the given input stream from being closed.

  ### Methods inherited from class org.apache.commons.io.input.ProxyInputStream

  `afterRead, available, beforeRead, handleIOException, mark, markSupported, read, read, read, reset, setReference, skip, unwrap`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### CloseShieldInputStream

    @Deprecated public CloseShieldInputStream(InputStream inputStream)
    Deprecated.
    Using this constructor prevents IDEs from warning if the underlying input stream is never closed. Use `wrap(InputStream)` instead.
    Constructs a proxy that shields the given input stream from being closed.
    Parameters:
      `inputStream` - underlying input stream.

- ## Method Details

  - ### builder

    public static CloseShieldInputStream.Builder builder()
    Constructs a new builder for `CloseShieldInputStream`.
    Returns:
      the new builder.
    Since:
      2.22.0

  - ### systemIn

    public static InputStream systemIn(InputStream inputStream)
    Constructs a proxy that only shields `System.in` from closing.
    Parameters:
      `inputStream` - the candidate input stream.
    Returns:
      the given stream or a proxy on `System.in`.
    Since:
      2.17.0

  - ### wrap

    public static CloseShieldInputStream wrap(InputStream inputStream)
    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

    public void close() throws IOException
    Applies the `onClose` function to the underlying input stream, replacing it with the result.

    By default, replaces the underlying input stream with a `ClosedInputStream` sentinel. The original input stream will remain open, but this proxy will appear closed.

    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`
    Overrides:
      `close` in class `ProxyInputStream`
    Throws:
      `IOException` - Thrown by the `onClose` function.