Package org.apache.arrow.util
Class AutoCloseables
java.lang.Object
org.apache.arrow.util.AutoCloseables
Utilities for AutoCloseable classes.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A closeable wrapper that will close the underlying closeables if a commit does not occur. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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> ac) Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one.static void
close
(Iterable<? extends AutoCloseable>... closeables) Callsclose(Iterable)
on the flattened list of closeables.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() anAutoCloseable
without throwing a (checked)Exception
.static Iterable<AutoCloseable>
iter
(AutoCloseable... ac) Convertsac
to aIterable
filtering out any null values.static AutoCloseable
noop()
Get an AutoCloseable that does nothing.rollbackable
(AutoCloseable... closeables) Creates anAutoCloseables.RollbackCloseable
from the given closeables.
-
Method Details
-
all
-
close
Closes all autoCloseables if not null and suppresses exceptions by adding them to t.- Parameters:
t
- the throwable to add suppressed exception toautoCloseables
- the closeables to close
-
close
Closes all autoCloseables if not null and suppresses exceptions by adding them to t.- Parameters:
t
- the throwable to add suppressed exception toautoCloseables
- the closeables to close
-
close
Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one.- Parameters:
autoCloseables
- the closeables to close- Throws:
Exception
-
close
Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one.- Parameters:
ac
- the closeables to close- Throws:
Exception
-
close
@SafeVarargs public static void close(Iterable<? extends AutoCloseable>... closeables) throws Exception Callsclose(Iterable)
on the flattened list of closeables.- Throws:
Exception
-
iter
Convertsac
to aIterable
filtering out any null values. -
rollbackable
Creates anAutoCloseables.RollbackCloseable
from the given closeables. -
closeNoChecked
close() anAutoCloseable
without throwing a (checked)Exception
. This wraps the close() call with a try-catch that will rethrow an Exception wrapped with aRuntimeException
, providing a way to call close() without having to do the try-catch everywhere or propagate the Exception.- Parameters:
autoCloseable
- the AutoCloseable to close; may be null- Throws:
RuntimeException
- if an Exception occurs; the Exception is wrapped by the RuntimeException
-
noop
Get an AutoCloseable that does nothing.- Returns:
- A do-nothing autocloseable
-