public final class UberCloser
extends java.lang.Object
Util class provides usability static methods to close instances of AutoCloseable or Destroyable,
or to perform any kind of dangerous close operations on any target.
There are two groups of methods, duplicating each other in arguments:
UberCloser.CloseException
Note: even though methods taking DangerousConsumer as operation to be performed
may be used to perform any kinds of operation - it is discouraged, since names of methods
and logged messages or thrown exceptions are explicitly say about 'closing' something. Performing any other
operation except actual closing or destroying may cause confusing code or error messages. Use Try to
perform any other kind of operation.
| Modifier and Type | Class and Description |
|---|---|
static class |
UberCloser.CloseException
Exception indicating an error happened during the closing process.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
close(java.lang.AutoCloseable closeable)
Equal to
close(AutoCloseable, String) with name produced from target object. |
static void |
close(java.lang.AutoCloseable closeable,
java.lang.String name)
Equal to
close(Object, DangerousConsumer, String)
where dangerous operation is AutoCloseable.close() |
static void |
close(Destroyable destroyable)
Equal to
close(Destroyable, String) with name produced from target object. |
static void |
close(Destroyable destroyable,
java.lang.String name)
Equal to
close(Object, DangerousConsumer, String)
where dangerous operation is Destroyable.destroy() |
static <T> void |
close(T target,
DangerousConsumer<T,?> operation)
Equal to
close(Object, DangerousConsumer, String) with name produced from target object. |
static <T> void |
close(T target,
DangerousConsumer<T,?> operation,
java.lang.String name)
If specified target is
null - nothing happens. |
static void |
closeQuietly(java.lang.AutoCloseable closeable)
Equal to
closeQuietly(AutoCloseable, String) with name produced from target object. |
static void |
closeQuietly(java.lang.AutoCloseable closeable,
java.lang.String name)
Equal to
closeQuietly(Object, DangerousConsumer, String)
where dangerous operation is AutoCloseable.close() |
static void |
closeQuietly(Destroyable destroyable)
Equal to
closeQuietly(Destroyable, String) with name produced from target object. |
static void |
closeQuietly(Destroyable destroyable,
java.lang.String name)
Equal to
closeQuietly(Object, DangerousConsumer, String)
where dangerous operation is Destroyable.destroy() |
static <T> void |
closeQuietly(T target,
DangerousConsumer<T,?> operation)
Equal to
closeQuietly(Object, DangerousConsumer, String) with name produced from target object. |
static <T> void |
closeQuietly(T target,
DangerousConsumer<T,?> operation,
java.lang.String name)
If specified target is
null - nothing happens. |
public static void close(java.lang.AutoCloseable closeable)
close(AutoCloseable, String) with name produced from target object.UberCloser.CloseExceptionclose(AutoCloseable, String)public static void close(java.lang.AutoCloseable closeable,
java.lang.String name)
close(Object, DangerousConsumer, String)
where dangerous operation is AutoCloseable.close()UberCloser.CloseExceptionclose(AutoCloseable)public static void close(Destroyable destroyable)
close(Destroyable, String) with name produced from target object.UberCloser.CloseExceptionclose(Destroyable, String)public static void close(Destroyable destroyable, java.lang.String name)
close(Object, DangerousConsumer, String)
where dangerous operation is Destroyable.destroy()UberCloser.CloseExceptionclose(Destroyable)public static <T> void close(T target,
DangerousConsumer<T,?> operation)
close(Object, DangerousConsumer, String) with name produced from target object.UberCloser.CloseExceptionclose(Object, DangerousConsumer, String)public static <T> void close(T target,
DangerousConsumer<T,?> operation,
java.lang.String name)
null - nothing happens. Otherwise specified dangerous operation
is performed on the specified target. If any exception was raised - new instance of the UberCloser.CloseException
is thrown with message containing specified name and with raised cause exception.UberCloser.CloseExceptionclose(Object, DangerousConsumer)public static void closeQuietly(java.lang.AutoCloseable closeable)
closeQuietly(AutoCloseable, String) with name produced from target object.closeQuietly(AutoCloseable, String)public static void closeQuietly(java.lang.AutoCloseable closeable,
java.lang.String name)
closeQuietly(Object, DangerousConsumer, String)
where dangerous operation is AutoCloseable.close()closeQuietly(AutoCloseable)public static void closeQuietly(Destroyable destroyable)
closeQuietly(Destroyable, String) with name produced from target object.closeQuietly(Destroyable, String)public static void closeQuietly(Destroyable destroyable, java.lang.String name)
closeQuietly(Object, DangerousConsumer, String)
where dangerous operation is Destroyable.destroy()closeQuietly(Destroyable)public static <T> void closeQuietly(T target,
DangerousConsumer<T,?> operation)
closeQuietly(Object, DangerousConsumer, String) with name produced from target object.public static <T> void closeQuietly(T target,
DangerousConsumer<T,?> operation,
java.lang.String name)
null - nothing happens. Otherwise specified
dangerous operation is performed on the specified target. If any exception
was raised - it is logged thru SLF4J logger with 'WARN' level.closeQuietly(Object, DangerousConsumer)