Class CloseShieldReader

All Implemented Interfaces:
Closeable, AutoCloseable, 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 Details

    • CloseShieldReader

      Deprecated.
      Using this constructor prevents IDEs from warning if the underlying reader is never closed. Use wrap(Reader) instead.
      Constructs a proxy that shields the given reader from being closed.
      Parameters:
      reader - underlying reader
  • Method Details

    • wrap

      public static CloseShieldReader wrap(Reader reader)
      Constructs 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 a ClosedReader sentinel. The original reader 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 ProxyReader