Class Closeables


  • public class Closeables
    extends java.lang.Object
    Since:
    3/8/17
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.io.Closeable NO_OP
      A closeable which does nothing
    • Constructor Summary

      Constructors 
      Constructor Description
      Closeables()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> CloseableProvider<T> closeableProvider​(T object)  
      static <T> CloseableProvider<T> closeableProvider​(T object, java.io.Closeable closer)  
      static void closeAll​(boolean throwIOException, boolean throwLast, java.io.Closeable... closeables)  
      static void closeAll​(java.io.Closeable... closeables)
      Close all closeables and throw any final exception
      static void closeAll​(java.util.Collection<java.io.Closeable> closeables)  
      static java.io.Closeable closeOnce​(java.io.Closeable closer)  
      static void closeQuietly​(java.io.Closeable... closeables)
      Close all closeables quietly
      static void closeQuietly​(java.util.Collection<java.io.Closeable> closeables)  
      static java.io.Closeable maybeCloseable​(java.lang.Object object)
      If the input object is a Closeable, return it, otherwise return a non-null Closeable which does nothing.
      static java.io.Closeable single​(boolean throwIOException, boolean throwLast, java.io.Closeable... closeables)
      Create a single Closeable which closes all of the specified closeables
      static java.io.Closeable single​(boolean throwIOException, java.io.Closeable... closeables)
      Create a single Closeable which closes all of the specified closeables
      static java.io.Closeable single​(boolean throwIOException, java.util.Collection<java.io.Closeable> closeables)
      Create a single Closeable which closes all of the specified closeables
      static java.io.Closeable single​(java.io.Closeable... closeables)
      Create a single Closeable which closes all of the specified closeables and throws IOExceptions
      static java.io.Closeable single​(java.util.Collection<java.io.Closeable> closeables)
      Create a single Closeable which closes all of the specified closeables and throws IOExceptions
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NO_OP

        public static final java.io.Closeable NO_OP
        A closeable which does nothing
    • Constructor Detail

      • Closeables

        public Closeables()
    • Method Detail

      • closeableProvider

        public static <T> CloseableProvider<T> closeableProvider​(T object)
      • closeOnce

        public static java.io.Closeable closeOnce​(java.io.Closeable closer)
      • closeableProvider

        public static <T> CloseableProvider<T> closeableProvider​(T object,
                                                                 java.io.Closeable closer)
      • maybeCloseable

        public static java.io.Closeable maybeCloseable​(java.lang.Object object)
        If the input object is a Closeable, return it, otherwise return a non-null Closeable which does nothing.
        Parameters:
        object - object which might be closeable
        Returns:
        a closeable
      • single

        public static java.io.Closeable single​(boolean throwIOException,
                                               java.util.Collection<java.io.Closeable> closeables)
        Create a single Closeable which closes all of the specified closeables
        Parameters:
        throwIOException - if true, throw any IOException encountered
        closeables - collection of closeables
        Returns:
        closeable
      • single

        public static java.io.Closeable single​(java.util.Collection<java.io.Closeable> closeables)
        Create a single Closeable which closes all of the specified closeables and throws IOExceptions
        Parameters:
        closeables - closeables
        Returns:
        closeable which silently closes all in the collection
      • single

        public static java.io.Closeable single​(java.io.Closeable... closeables)
        Create a single Closeable which closes all of the specified closeables and throws IOExceptions
        Parameters:
        closeables - closeables
        Returns:
        closeable which silently closes all in the array
      • single

        public static java.io.Closeable single​(boolean throwIOException,
                                               java.io.Closeable... closeables)
        Create a single Closeable which closes all of the specified closeables
        Parameters:
        throwIOException - if true, throw the final IOException encountered
        closeables - array of closeables
        Returns:
        closeable
      • single

        public static java.io.Closeable single​(boolean throwIOException,
                                               boolean throwLast,
                                               java.io.Closeable... closeables)
        Create a single Closeable which closes all of the specified closeables
        Parameters:
        throwIOException - if true, throw an IOException if encountered, otherwise do not throw anything
        throwLast - if true, only throw the last IOException encountered, otherwise throw the first
        closeables - array of closeables
        Returns:
        closeable
      • closeQuietly

        public static void closeQuietly​(java.util.Collection<java.io.Closeable> closeables)
      • closeAll

        public static void closeAll​(java.util.Collection<java.io.Closeable> closeables)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • closeAll

        public static void closeAll​(java.io.Closeable... closeables)
                             throws java.io.IOException
        Close all closeables and throw any final exception
        Parameters:
        closeables -
        Throws:
        java.io.IOException
      • closeQuietly

        public static void closeQuietly​(java.io.Closeable... closeables)
        Close all closeables quietly
        Parameters:
        closeables -
      • closeAll

        public static void closeAll​(boolean throwIOException,
                                    boolean throwLast,
                                    java.io.Closeable... closeables)
                             throws java.io.IOException
        Throws:
        java.io.IOException