- java.lang.Object
-
- de.carne.util.AutoCloseables
-
public final class AutoCloseables extends java.lang.ObjectUtility class providing AutoCloseable related functions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(@Nullable java.lang.Object object)Closes a potential AutoCloseable.static voidcloseAll(java.lang.AutoCloseable... closeables)Closes multiple AutoCloseables in a safe manner.static voidcloseAll(java.lang.Iterable<java.lang.AutoCloseable> closeables)Closes multiple AutoCloseables in a safe manner.static voidsafeClose(@Nullable java.lang.Object object)Close potential AutoCloseable.static voidsafeClose(java.lang.Throwable exception, @Nullable java.lang.Object object)Close potential AutoCloseable.
-
-
-
Method Detail
-
close
public static void close(@Nullable java.lang.Object object) throws java.lang.ExceptionCloses a potential AutoCloseable.An Exception caused by AutoCloseable.close() is forwarded to the caller.
- Parameters:
object- the object to check and close.- Throws:
java.lang.Exception- ifAutoCloseable.close()fails.
-
closeAll
public static void closeAll(java.lang.AutoCloseable... closeables) throws java.lang.ExceptionCloses multiple AutoCloseables in a safe manner.This function ensures that for every submitted non-null AutoCloseable instance the corresponding AutoCloseable.close() method is called. The first encountered Exception will be forwarded to the caller. Any additional Exception will be added to the initial one as a suppressed exception.
- Parameters:
closeables- the AutoCloseables to close (may containnullvalues).- Throws:
java.lang.Exception- if one or moreAutoCloseable.close()calls fail.
-
closeAll
public static void closeAll(java.lang.Iterable<java.lang.AutoCloseable> closeables) throws java.lang.ExceptionCloses multiple AutoCloseables in a safe manner.This function ensures that for every submitted AutoCloseable instance the corresponding AutoCloseable.close() method is called. The first encountered Exception will be forwarded to the caller. Any additional Exception will be added to the initial one as a suppressed exception.
- Parameters:
closeables- the AutoCloseables to close.- Throws:
java.lang.Exception- if one or moreAutoCloseable.close()calls fail.
-
safeClose
public static void safeClose(@Nullable java.lang.Object object)
Close potential AutoCloseable.An Exception caused by AutoCloseable.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 AutoCloseable.An Exception caused by AutoCloseable.close() is suppressed and added to the given outer exception.
- Parameters:
exception- the currently handled outer exception.object- the object to check and close.
-
-