@@ -395,21 +395,16 @@ public static void close(final Closeable... closeables) throws IOException {
395395 }
396396
397397 /**
398- * Closes the entries in the given {@link Stream} as null-safe operations,
399- * and closes the underlying {@code Stream}.
398+ * Closes the entries in the given {@link Stream} as null-safe operations.
400399 *
401400 * @param <T> The element type.
402- * @param closeables The resource(s) to close, may be null.
401+ * @param closeables The resource(s) to close, may be null or empty .
403402 * @throws IOExceptionList if an I/O error occurs.
404403 * @since 2.12.0
405404 */
406405 public static <T extends Closeable > void close (final Stream <T > closeables ) throws IOExceptionList {
407406 if (closeables != null ) {
408- try {
409- IOConsumer .forEachIndexed (closeables , IOUtils ::close );
410- } finally {
411- closeables .close ();
412- }
407+ IOConsumer .forEachIndexed (closeables .filter (Objects ::nonNull ), IOUtils ::close );
413408 }
414409 }
415410
@@ -434,24 +429,19 @@ public static void close(final Closeable closeable, final IOConsumer<IOException
434429 }
435430
436431 /**
437- * Closes the entries in the given {@link Stream} as null-safe operations,
438- * and closes the underlying {@code Stream}.
432+ * Closes the entries in the given {@link Stream} as null-safe operations.
439433 *
440434 * @param <T> The element type.
441435 * @param consumer Consume the IOException thrown by {@link Closeable#close()}.
442- * @param closeables The resource(s) to close, may be null.
436+ * @param closeables The resource(s) to close, may be null or empty .
443437 * @throws IOException if an I/O error occurs.
444438 */
445439 public static <T extends Closeable > void close (final IOConsumer <IOException > consumer , final Stream <T > closeables ) throws IOException {
446- if (closeables != null ) {
447- try {
448- close (closeables );
449- } catch (final IOException e ) {
450- if (consumer != null ) {
451- consumer .accept (e );
452- }
453- } finally {
454- closeables .close ();
440+ try {
441+ close (closeables );
442+ } catch (final IOException e ) {
443+ if (consumer != null ) {
444+ consumer .accept (e );
455445 }
456446 }
457447 }
@@ -604,40 +594,30 @@ public static void closeQuietly(final Closeable closeable, final Consumer<IOExce
604594 }
605595
606596 /**
607- * Closes the given {@link Stream} as a null-safe operation while consuming IOException by the given {@code consumer},
608- * and closes the underlying {@code Stream}.
597+ * Closes the given {@link Stream} as a null-safe operation while consuming IOException by the given {@code consumer}.
609598 *
610599 * @param <T> The element type.
611- * @param closeables The resource(s) to close, may be null.
600+ * @param closeables The resource(s) to close, may be null or empty .
612601 * @since 2.12.0
613602 */
614603 public static <T extends Closeable > void closeQuietly (final Stream <T > closeables ) {
615604 closeQuietly (null , closeables );
616605 }
617606
618607 /**
619- * Closes the given {@link Stream} as a null-safe operation while consuming IOException by the given {@code consumer},
620- * and closes the underlying {@code Stream}.
608+ * Closes the given {@link Stream} as a null-safe operation while consuming IOException by the given {@code consumer}.
621609 *
622610 * @param <T> The element type.
623- * @param consumer Consume the IOException thrown by {@link Closeable#close()}.
624- * @param closeables The resource(s) to close, may be null.
611+ * @param consumer Consume the IOException thrown by {@link Closeable#close()}, may be null .
612+ * @param closeables The resource(s) to close, may be null or empty .
625613 * @since 2.12.0
626614 */
627615 public static <T extends Closeable > void closeQuietly (final Consumer <IOException > consumer , final Stream <T > closeables ) {
628- if (closeables != null ) {
629- try {
630- close (closeables );
631- } catch (final IOException e ) {
632- if (consumer != null ) {
633- consumer .accept (e );
634- }
635- } finally {
636- try {
637- closeables .close ();
638- } catch (Exception e ) {
639- // Do nothing.
640- }
616+ try {
617+ close (closeables );
618+ } catch (final IOException e ) {
619+ if (consumer != null ) {
620+ consumer .accept (e );
641621 }
642622 }
643623 }
0 commit comments