public static void close ( Iterable < ? extends Closeable > closeables ) throws IOException { IOException first = null ; for ( final Closeable c : closeables ) { if ( c == null ) { LOG . debug ( "trying to call .close() on null reference" ) ; continue ; } try { c . close ( ) ; } catch ( final IOException e ) { if ( first == null ) { first = e ; } else { first . addSuppressed ( e ) ; } } } if ( first != null ) { throw first ; } }
Closes the given Closeables and collects all occurring exceptions as suppressed exception to the exception that occurred first .