public final class IOUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends AutoCloseable,E extends Throwable> |
close(BiFunction<String,Throwable,E> constructor,
Collection<T> closeables)
Close all ofthe given closeables, and if something goes wrong, use the given constructor to create a
Throwable instance with the specific cause
attached. |
static <T extends AutoCloseable,E extends Throwable> |
close(BiFunction<String,Throwable,E> constructor,
T... closeables)
Close all ofthe given closeables, and if something goes wrong, use the given constructor to create a
Throwable instance with the specific cause
attached. |
static <T extends AutoCloseable> |
closeAll(Collection<T> closeables)
Closes given
collection of closeables. |
static <T extends AutoCloseable> |
closeAll(T... closeables)
Closes given array of
closeables. |
static <T extends AutoCloseable> |
closeAllSilently(Collection<T> closeables)
Closes given
collection of closeables ignoring all exceptions. |
static <T extends AutoCloseable> |
closeAllSilently(T... closeables)
Closes given array of
closeables ignoring all exceptions. |
static <T extends AutoCloseable> |
closeAllUnchecked(Collection<T> closeables)
Close all the provided
closeables, chaining exceptions, if any, into a single UncheckedIOException. |
static <T extends AutoCloseable> |
closeAllUnchecked(T... closeables)
Close all the provided
closeables, chaining exceptions, if any, into a single UncheckedIOException. |
public static <T extends AutoCloseable> void closeAll(Collection<T> closeables) throws IOException
collection of closeables.T - the type of closeablecloseables - the closeables to closeIOException - if an exception was thrown by one of the close methods.closeAll(AutoCloseable[])public static <T extends AutoCloseable> void closeAllUnchecked(Collection<T> closeables) throws UncheckedIOException
closeables, chaining exceptions, if any, into a single UncheckedIOException.T - the type of closeable.closeables - to call close on.UncheckedIOException - if any exception is thrown from any of the closeables.@SafeVarargs public static <T extends AutoCloseable> void closeAllUnchecked(T... closeables) throws UncheckedIOException
closeables, chaining exceptions, if any, into a single UncheckedIOException.T - the type of closeable.closeables - to call close on.UncheckedIOException - if any exception is thrown from any of the closeables.public static <T extends AutoCloseable> void closeAllSilently(Collection<T> closeables)
collection of closeables ignoring all exceptions.T - the type of closeablecloseables - the closeables to closecloseAll(AutoCloseable[])@SafeVarargs public static <T extends AutoCloseable> void closeAll(T... closeables) throws IOException
closeables. If any AutoCloseable.close() call throws
IOException than it will be rethrown to the caller after calling AutoCloseable.close()
on other given resources. If more than one AutoCloseable.close() throw than resulting exception will
have suppressed exceptions. See Throwable.addSuppressed(Throwable)T - the type of closeablecloseables - the closeables to closeIOException - if an exception was thrown by one of the close methods.@SafeVarargs public static <T extends AutoCloseable> void closeAllSilently(T... closeables)
closeables ignoring all exceptions.T - the type of closeablecloseables - the closeables to closepublic static <T extends AutoCloseable,E extends Throwable> void close(BiFunction<String,Throwable,E> constructor, Collection<T> closeables) throws E extends Throwable
Throwable instance with the specific cause
attached. The remaining closeables will still be closed, in that case, and if they in turn throw any exceptions then these will be attached as
suppressed exceptions.T - the type of things to close.E - the type of the parent exception.constructor - The function used to construct the parent throwable that will have the first thrown exception attached as a cause, and any
remaining exceptions attached as suppressed exceptions. If this function returns null, then the exception is ignored.closeables - an iterator of all the things to close, in order.E - when any AutoCloseable.close() throws exceptionE extends Throwable@SafeVarargs public static <T extends AutoCloseable,E extends Throwable> void close(BiFunction<String,Throwable,E> constructor, T... closeables) throws E extends Throwable
Throwable instance with the specific cause
attached. The remaining closeables will still be closed, in that case, and if they in turn throw any exceptions then these will be attached as
suppressed exceptions.T - the type of things to close.E - the type of the parent exception.constructor - The function used to construct the parent throwable that will have the first thrown exception attached as a cause, and any
remaining exceptions attached as suppressed exceptions. If this function returns null, then the exception is ignored.closeables - all the things to close, in order.E - when any AutoCloseable.close() throws exceptionE extends ThrowableCopyright © 2016–2021 MWARE SOLUTIONS. All rights reserved.