Class AutoCloseables

java.lang.Object
org.apache.arrow.util.AutoCloseables

public final class AutoCloseables extends Object
Utilities for AutoCloseable classes.
  • Method Details

    • all

      public static AutoCloseable all(Collection<? extends AutoCloseable> autoCloseables)
      Returns a new AutoCloseable that calls close(Iterable) on autoCloseables when close is called.
    • close

      public static void close(Throwable t, AutoCloseable... autoCloseables)
      Closes all autoCloseables if not null and suppresses exceptions by adding them to t.
      Parameters:
      t - the throwable to add suppressed exception to
      autoCloseables - the closeables to close
    • close

      public static void close(Throwable t, Iterable<? extends AutoCloseable> autoCloseables)
      Closes all autoCloseables if not null and suppresses exceptions by adding them to t.
      Parameters:
      t - the throwable to add suppressed exception to
      autoCloseables - the closeables to close
    • close

      public static void close(AutoCloseable... autoCloseables) throws Exception
      Closes all autoCloseables if not null and suppresses subsequent exceptions if more than one.
      Parameters:
      autoCloseables - the closeables to close
      Throws:
      Exception
    • close

      public static void close(Iterable<? extends AutoCloseable> ac) throws Exception
      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
      Calls close(Iterable) on the flattened list of closeables.
      Throws:
      Exception
    • iter

      public static Iterable<AutoCloseable> iter(AutoCloseable... ac)
      Converts ac to a Iterable filtering out any null values.
    • rollbackable

      public static AutoCloseables.RollbackCloseable rollbackable(AutoCloseable... closeables)
      Creates an AutoCloseables.RollbackCloseable from the given closeables.
    • closeNoChecked

      public static void closeNoChecked(AutoCloseable autoCloseable)
      close() an 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.
      Parameters:
      autoCloseable - the AutoCloseable to close; may be null
      Throws:
      RuntimeException - if an Exception occurs; the Exception is wrapped by the RuntimeException
    • noop

      public static AutoCloseable noop()
      Get an AutoCloseable that does nothing.
      Returns:
      A do-nothing autocloseable