Package org.agrona

Class CloseHelper

java.lang.Object
org.agrona.CloseHelper

public final class CloseHelper extends Object
Utility functions to help with using AutoCloseable resources. If a null exception is passed then it is ignored.
  • Constructor Details

    • CloseHelper

      private CloseHelper()
  • Method Details

    • quietClose

      public static void quietClose(AutoCloseable closeable)
      Quietly close a AutoCloseable dealing with nulls and exceptions.
      Parameters:
      closeable - to be closed.
    • quietCloseAll

      public static void quietCloseAll(Collection<? extends AutoCloseable> closeables)
      Close all closeables in closeables. All exceptions and nulls will be ignored.
      Parameters:
      closeables - to be closed.
    • quietCloseAll

      public static void quietCloseAll(AutoCloseable... closeables)
      Close all closeables in closeables. All exceptions and nulls will be ignored.
      Parameters:
      closeables - to be closed.
    • close

      public static void close(AutoCloseable closeable)
      Close a AutoCloseable dealing with nulls and exceptions. This version re-throws exceptions as runtime exceptions.
      Parameters:
      closeable - to be closed.
    • closeAll

      public static void closeAll(Collection<? extends AutoCloseable> closeables)
      Close all provided closeables. If any of them throw then throw that exception. If multiple closeables throw an exception when being closed, then throw an exception that contains all of them as suppressed exceptions.
      Parameters:
      closeables - to be closed.
    • closeAll

      public static void closeAll(AutoCloseable... closeables)
      Close all provided closeables. If any of them throw then throw that exception. If multiple closeables throw an exception when being closed, then throw an exception that contains all of them as suppressed exceptions.
      Parameters:
      closeables - to be closed.
    • close

      public static void close(ErrorHandler errorHandler, AutoCloseable closeable)
      Close a AutoCloseable delegating exceptions to the ErrorHandler.
      Parameters:
      errorHandler - to delegate exceptions to.
      closeable - to be closed.
    • closeAll

      public static void closeAll(ErrorHandler errorHandler, Collection<? extends AutoCloseable> closeables)
      Close all closeables and delegate exceptions to the ErrorHandler.
      Parameters:
      errorHandler - to delegate exceptions to.
      closeables - to be closed.
    • closeAll

      public static void closeAll(ErrorHandler errorHandler, AutoCloseable... closeables)
      Close all closeables and delegate exceptions to the ErrorHandler.
      Parameters:
      errorHandler - to delegate exceptions to.
      closeables - to be closed.