public final class AutoCloseables extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
AutoCloseables.RollbackCloseable
A closeable wrapper that will close the underlying closeables if a commit does not occur.
|
| Modifier and Type | Method and Description |
|---|---|
static AutoCloseable |
all(Collection<? extends AutoCloseable> autoCloseables)
|
static void |
close(AutoCloseable... autoCloseables)
Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one.
|
static void |
close(Iterable<? extends AutoCloseable>... closeables)
Calls
close(Iterable) on the flattened list of closeables. |
static void |
close(Iterable<? extends AutoCloseable> ac)
Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one.
|
static void |
close(Throwable t,
AutoCloseable... autoCloseables)
Closes all autoCloseables if not null and suppresses exceptions by adding them to t.
|
static void |
close(Throwable t,
Iterable<? extends AutoCloseable> autoCloseables)
Closes all autoCloseables if not null and suppresses exceptions by adding them to t.
|
static void |
closeNoChecked(AutoCloseable autoCloseable)
close() an
AutoCloseable without throwing a (checked)
Exception. |
static Iterable<AutoCloseable> |
iter(AutoCloseable... ac)
Converts
ac to a Iterable filtering out any null values. |
static AutoCloseable |
noop()
Get an AutoCloseable that does nothing.
|
static AutoCloseables.RollbackCloseable |
rollbackable(AutoCloseable... closeables)
Creates an
AutoCloseables.RollbackCloseable from the given closeables. |
public static AutoCloseable all(Collection<? extends AutoCloseable> autoCloseables)
public static void close(Throwable t, AutoCloseable... autoCloseables)
t - the throwable to add suppressed exception toautoCloseables - the closeables to closepublic static void close(Throwable t, Iterable<? extends AutoCloseable> autoCloseables)
t - the throwable to add suppressed exception toautoCloseables - the closeables to closepublic static void close(AutoCloseable... autoCloseables) throws Exception
autoCloseables - the closeables to closeExceptionpublic static void close(Iterable<? extends AutoCloseable> ac) throws Exception
ac - the closeables to closeException@SafeVarargs public static void close(Iterable<? extends AutoCloseable>... closeables) throws Exception
close(Iterable) on the flattened list of closeables.Exceptionpublic static Iterable<AutoCloseable> iter(AutoCloseable... ac)
ac to a Iterable filtering out any null values.public static AutoCloseables.RollbackCloseable rollbackable(AutoCloseable... closeables)
AutoCloseables.RollbackCloseable from the given closeables.public static void closeNoChecked(AutoCloseable autoCloseable)
AutoCloseable without throwing a (checked)
Exception. This wraps the close() call with a
try-catch that will rethrow an Exception wrapped with a
RuntimeException, providing a way to call close()
without having to do the try-catch everywhere or propagate the Exception.autoCloseable - the AutoCloseable to close; may be nullRuntimeException - if an Exception occurs; the Exception is
wrapped by the RuntimeExceptionpublic static AutoCloseable noop()
Copyright © 2024 The Apache Software Foundation. All rights reserved.