Class IoTools.Quiet<C extends AutoCloseable>

java.lang.Object
de.aristaflow.adept2.util.io.IoTools.Quiet<C>
Type Parameters:
C - The type of the closeable of which to log any exception from AutoCloseable.close().
All Implemented Interfaces:
AutoCloseable
Enclosing class:
IoTools

public static class IoTools.Quiet<C extends AutoCloseable> extends Object
This class wraps an AutoCloseable and logs the exception from closing.
  • Field Details

    • logger

      protected final Logger logger
      The logger to which to log an occurred exception or null to wrap the exception as RuntimeException.
    • condition

      protected final Supplier<Boolean> condition
      The optional condition allowing for conditional closing. If this is null, unconditional closing will apply.
    • wrapped

      protected final C extends AutoCloseable wrapped
      The wrapped AutoCloseable.
  • Constructor Details

    • Quiet

      protected Quiet(C wrapped, Logger logger)
      Creates a new unconditional closeable wrapping the designated AutoCloseable logging or wrapping any exception from AutoCloseable.close().
      Parameters:
      wrapped - The wrapped AutoCloseable.
      logger - The logger to which to log an occurred exception or null to wrap the exception as RuntimeException.
    • Quiet

      protected Quiet(Supplier<Boolean> condition, C wrapped, Logger logger)
      Creates a new conditional closeable wrapping the designated AutoCloseable logging or wrapping any exception from AutoCloseable.close().
      Parameters:
      condition - The optional condition allowing for conditional closing or null for unconditional closing.
      wrapped - The wrapped AutoCloseable.
      logger - The logger to which to log an occurred exception or null to wrap the exception as RuntimeException.
  • Method Details

    • close

      public void close()
      Closes the wrapped AutoCloseable (depending on the condition) and logs any Exception.
    • evalCond

      protected boolean evalCond()
      Gets whether to close or not.
      Returns:
      Whether to close or not.
    • getWrapped

      public C getWrapped()
      Gets the wrapped AutoCloseable.
      Returns:
      The wrapped AutoCloseable.