Package org.agrona

Class CloseHelper


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

      Constructors 
      Modifier Constructor Description
      private CloseHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close​(java.lang.AutoCloseable closeable)
      Close a AutoCloseable dealing with nulls and exceptions.
      static void close​(ErrorHandler errorHandler, java.lang.AutoCloseable closeable)
      Close a AutoCloseable delegating exceptions to the ErrorHandler.
      static void closeAll​(java.lang.AutoCloseable... closeables)
      Close all provided closeables.
      static void closeAll​(java.util.Collection<? extends java.lang.AutoCloseable> closeables)
      Close all provided closeables.
      static void closeAll​(ErrorHandler errorHandler, java.lang.AutoCloseable... closeables)
      Close all closeables and delegate exceptions to the ErrorHandler.
      static void closeAll​(ErrorHandler errorHandler, java.util.Collection<? extends java.lang.AutoCloseable> closeables)
      Close all closeables and delegate exceptions to the ErrorHandler.
      static void quietClose​(java.lang.AutoCloseable closeable)
      Quietly close a AutoCloseable dealing with nulls and exceptions.
      static void quietCloseAll​(java.lang.AutoCloseable... closeables)
      Close all closeables in closeables.
      static void quietCloseAll​(java.util.Collection<? extends java.lang.AutoCloseable> closeables)
      Close all closeables in closeables.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CloseHelper

        private CloseHelper()
    • Method Detail

      • quietClose

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

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

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

        public static void close​(java.lang.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​(java.util.Collection<? extends java.lang.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​(java.lang.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,
                                 java.lang.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,
                                    java.util.Collection<? extends java.lang.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,
                                    java.lang.AutoCloseable... closeables)
        Close all closeables and delegate exceptions to the ErrorHandler.
        Parameters:
        errorHandler - to delegate exceptions to.
        closeables - to be closed.