Module de.carne
Package de.carne.io

Class Closeables


  • public final class Closeables
    extends java.lang.Object
    Utility class providing Closeable related functions.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close​(@Nullable java.lang.Object object)
      Closes a potential Closeable.
      static void closeAll​(java.io.Closeable... closeables)
      Closes multiple Closeables in a safe manner.
      static void closeAll​(java.lang.Iterable<java.io.Closeable> closeables)
      Closes multiple Closeables in a safe manner.
      static void safeClose​(@Nullable java.lang.Object object)
      Close potential Closeable.
      static void safeClose​(java.lang.Throwable exception, @Nullable java.lang.Object object)
      Close potential Closeable.
      • Methods inherited from class java.lang.Object

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

      • close

        public static void close​(@Nullable java.lang.Object object)
                          throws java.io.IOException
        Closes a potential Closeable.

        An IOException caused by Closeable.close() is forwarded to the caller.

        Parameters:
        object - the object to check and close.
        Throws:
        java.io.IOException - if Closeable.close() fails.
      • closeAll

        public static void closeAll​(java.io.Closeable... closeables)
                             throws java.io.IOException
        Closes multiple Closeables in a safe manner.

        This function ensures that for every submitted non-null Closeable instance the corresponding Closeable.close() method is called. The first encountered IOException will be forwarded to the caller. Any additional IOException will be added to the initial one as a suppressed exception.

        Parameters:
        closeables - the Closeables to close (may contain null values).
        Throws:
        java.io.IOException - if one or more Closeable.close() calls fail.
      • closeAll

        public static void closeAll​(java.lang.Iterable<java.io.Closeable> closeables)
                             throws java.io.IOException
        Closes multiple Closeables in a safe manner.

        This function ensures that for every submitted non-null Closeable instance the corresponding Closeable.close() method is called. The first encountered IOException will be forwarded to the caller. Any additional IOException will be added to the initial one as a suppressed exception.

        Parameters:
        closeables - the Closeables to close (may contain null values).
        Throws:
        java.io.IOException - if one or more Closeable.close() calls fail.
      • safeClose

        public static void safeClose​(@Nullable java.lang.Object object)
        Close potential Closeable.

        An IOException caused by Closeable.close() is ignored.

        Parameters:
        object - the object to check and close.
      • safeClose

        public static void safeClose​(java.lang.Throwable exception,
                                     @Nullable java.lang.Object object)
        Close potential Closeable.

        An IOException caused by Closeable.close() is suppressed and added to the given outer exception.

        Parameters:
        exception - the currently handled outer exception.
        object - the object to check and close.