Class CloseShieldWriter

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

    • CloseShieldWriter

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

    • wrap

      public static CloseShieldWriter wrap(Writer writer)
      Constructs 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 a ClosedWriter sentinel. The original writer 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 ProxyWriter