Class KiwiCloseables


  • @Beta
    public final class KiwiCloseables
    extends Object
    Static utilities related to Closeable and other objects that can be "closed", whether they implement Closeable or not.
    • Method Detail

      • closeAllQuietly

        public static void closeAllQuietly​(Object... objects)
        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.CloseDescriptor to 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:
        closeAll(Object...)
      • closeQuietly

        public static void closeQuietly​(KiwiCloseables.CloseDescriptor descriptor)
        Close an object described by the KiwiCloseables.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.CloseDescriptor refers to a non-public method, this method will attempt to invoke it. But this may result in an IllegalAccessException.

        Parameters:
        descriptor - the description of an object and its "close" method
        See Also:
        close(CloseDescriptor)
      • closeQuietly

        public static void closeQuietly​(@Nullable Closeable closeable)
        Close the given instance of Closeable, 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 - the Closeable to close
        See Also:
        close(Closeable)