Class Closeables


  • public final class Closeables
    extends Object
    Common utility methods for Closeables.
    • Method Detail

      • closeSilently

        public static void closeSilently​(AutoCloseable... resources)
        Closes the provided resources ignoring any errors which occurred.
        Parameters:
        resources - The resources to be closed, which may be null.
      • closeSilently

        public static void closeSilently​(Closeable... resources)
        Closes the provided resources ignoring any errors which occurred.
        Parameters:
        resources - The resources to be closed, which may be null.
      • closeSilently

        public static void closeSilently​(Iterable<? extends AutoCloseable> resources)
        Closes the provided resources ignoring any errors which occurred.
        Parameters:
        resources - The resources to be closed, which may be null.
      • closeSilentlyAsync

        public static Runnable closeSilentlyAsync​(AutoCloseable... resources)
        Closes asynchronously the provided resources ignoring any errors which occurred.

        Meant to be used with Promise.thenAlways(Runnable) or Promise.thenFinally(Runnable):

        Usage example with HTTP Framework:

         Request request = new Request();
           Promise<Response, NeverThrowsException> promise =
                   handler.handle(context, request)
                          .thenAlways(closeSilentlyAsync(request));
         
         
        Parameters:
        resources - The resources to be closed, which may be null.
        Returns:
        Runnable to be used as callback
      • closeSilentlyAsync

        public static Runnable closeSilentlyAsync​(Closeable... resources)
        Closes asynchronously the provided resources ignoring any errors which occurred.

        Meant to be used with Promise.thenAlways(Runnable) or Promise.thenFinally(Runnable):

        Usage example with HTTP Framework:

         Request request = new Request();
           Promise<Response, NeverThrowsException> promise =
                   handler.handle(context, request)
                          .thenAlways(closeSilentlyAsync(request));
         
         
        Parameters:
        resources - The resources to be closed, which may be null.
        Returns:
        Runnable to be used as callback