Package de.aristaflow.adept2.util.io
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 fromAutoCloseable.close().
- All Implemented Interfaces:
AutoCloseable
- Enclosing class:
- IoTools
This class wraps an
AutoCloseable and logs the exception from
closing.-
Field Summary
FieldsModifier and TypeFieldDescriptionThe optional condition allowing for conditional closing.protected final LoggerThe logger to which to log an occurred exception ornullto wrap the exception asRuntimeException.protected final CThe wrappedAutoCloseable. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new unconditional closeable wrapping the designatedAutoCloseablelogging or wrapping any exception fromAutoCloseable.close().protectedCreates a new conditional closeable wrapping the designatedAutoCloseablelogging or wrapping any exception fromAutoCloseable.close(). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected booleanevalCond()Gets whether to close or not.Gets the wrappedAutoCloseable.
-
Field Details
-
logger
The logger to which to log an occurred exception ornullto wrap the exception asRuntimeException. -
condition
The optional condition allowing for conditional closing. If this isnull, unconditional closing will apply. -
wrapped
The wrappedAutoCloseable.
-
-
Constructor Details
-
Quiet
Creates a new unconditional closeable wrapping the designatedAutoCloseablelogging or wrapping any exception fromAutoCloseable.close().- Parameters:
wrapped- The wrappedAutoCloseable.logger- The logger to which to log an occurred exception ornullto wrap the exception asRuntimeException.
-
Quiet
Creates a new conditional closeable wrapping the designatedAutoCloseablelogging or wrapping any exception fromAutoCloseable.close().- Parameters:
condition- The optional condition allowing for conditional closing ornullfor unconditional closing.wrapped- The wrappedAutoCloseable.logger- The logger to which to log an occurred exception ornullto wrap the exception asRuntimeException.
-
-
Method Details
-
close
public void close() -
evalCond
protected boolean evalCond()Gets whether to close or not.- Returns:
- Whether to close or not.
-
getWrapped
Gets the wrappedAutoCloseable.- Returns:
- The wrapped
AutoCloseable.
-