Class KiwiCloseables
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA description of how to close a specific object.static classRepresents the result of an attempt to close an object. -
Method Summary
Modifier and TypeMethodDescriptionstatic KiwiCloseables.CloseResultClose the given instance ofCloseable.static KiwiCloseables.CloseResultclose(KiwiCloseables.CloseDescriptor descriptor) Close an object described by theKiwiCloseables.CloseDescriptor.static List<KiwiCloseables.CloseResult>Close all the given objects, and return a singleKiwiCloseables.CloseResultcorresponding to each input object in order.static voidcloseAllQuietly(Object... objects) Close all the given objects, suppressing any exceptions.static voidcloseQuietly(@Nullable Closeable closeable) Close the given instance ofCloseable, and suppress any exception.static voidcloseQuietly(KiwiCloseables.CloseDescriptor descriptor) Close an object described by theKiwiCloseables.CloseDescriptor, and suppress any exception.
-
Method Details
-
closeAllQuietly
Close all the given objects, suppressing any exceptions. Suppressed exceptions are logged at WARN level.Before using this method, consider whether it is safe to ignore exceptions thrown while closing an I/O resource. It might be safe when using "input" objects such as when reading a file or an input stream, but it generally is not safe when writing a file or to an output stream. Consider using
closeAll(Object...).The objects may be instances of
KiwiCloseables.CloseDescriptorto provide a custom name for the "close" method. Otherwise, each object is assumed to use the default method name "close".- Parameters:
objects- the objects to close- See Also:
-
closeQuietly
Close an object described by theKiwiCloseables.CloseDescriptor, and suppress any exception. Suppressed exceptions are logged at WARN level.Before using this method, consider whether it is safe to ignore exceptions thrown while closing an I/O resource. It might be safe when using "input" objects such as when reading a file or an input stream, but it generally is not safe when writing a file or to an output stream. Consider using
close(CloseDescriptor).If the
KiwiCloseables.CloseDescriptorrefers to a non-public method, this method will attempt to invoke it. But this may result in anIllegalAccessException.- Parameters:
descriptor- the description of an object and its "close" method- See Also:
-
closeQuietly
Close the given instance ofCloseable, and suppress any exception. Suppressed exceptions are logged at WARN level.Before using this method, consider whether it is safe to ignore exceptions thrown while closing an I/O resource. It might be safe when using "input" objects such as when reading a file or an input stream, but it generally is not safe when writing a file or to an output stream. Consider using
close(Closeable).- Parameters:
closeable- theCloseableto close- See Also:
-
closeAll
Close all the given objects, and return a singleKiwiCloseables.CloseResultcorresponding to each input object in order.The objects may be instances of
KiwiCloseables.CloseDescriptorto provide a custom name for the "close" method. Otherwise, each object is assumed to use the default method name "close".- Parameters:
objects- the objects to close- Returns:
- a list of
KiwiCloseables.CloseResultcontaining the result for each attempted close operation
-
close
Close an object described by theKiwiCloseables.CloseDescriptor.If the
KiwiCloseables.CloseDescriptorrefers to a non-public method, this method will attempt to invoke it. But this may result in anIllegalAccessException.- Parameters:
descriptor- the description of an object and its "close" method- Returns:
- the
KiwiCloseables.CloseResult
-
close
Close the given instance ofCloseable.- Parameters:
closeable- theCloseableto close- Returns:
- the
KiwiCloseables.CloseResult
-