- java.lang.Object
-
- de.carne.io.Closeables
-
public final class Closeables extends java.lang.ObjectUtility class providing Closeable 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 Closeable.static voidcloseAll(java.io.Closeable... closeables)Closes multiple Closeables in a safe manner.static voidcloseAll(java.lang.Iterable<java.io.Closeable> closeables)Closes multiple Closeables in a safe manner.static voidsafeClose(@Nullable java.lang.Object object)Close potential Closeable.static voidsafeClose(java.lang.Throwable exception, @Nullable java.lang.Object object)Close potential Closeable.
-
-
-
Method Detail
-
close
public static void close(@Nullable java.lang.Object object) throws java.io.IOExceptionCloses 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- ifCloseable.close()fails.
-
closeAll
public static void closeAll(java.io.Closeable... closeables) throws java.io.IOExceptionCloses 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 containnullvalues).- Throws:
java.io.IOException- if one or moreCloseable.close()calls fail.
-
closeAll
public static void closeAll(java.lang.Iterable<java.io.Closeable> closeables) throws java.io.IOExceptionCloses 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 containnullvalues).- Throws:
java.io.IOException- if one or moreCloseable.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.
-
-