jochenw commented on a change in pull request #300:
URL: https://github.com/apache/commons-io/pull/300#discussion_r750003970



##########
File path: src/main/java/org/apache/commons/io/IOUtils.java
##########
@@ -414,6 +433,48 @@ public static void close(final Closeable closeable, final 
IOConsumer<IOException
         }
     }
 
+    /**
+     * Closes the entries in the given {@link Stream} as null-safe operations,
+     * and closes the underlying {@code Stream}.
+     *
+     * @param <T> The element type.
+     * @param consumer Consume the IOException thrown by {@link 
Closeable#close()}.
+     * @param closeables The resource(s) to close, may be null.
+     * @throws IOException if an I/O error occurs.
+     */
+    public static <T extends Closeable> void close(final 
IOConsumer<IOException> consumer, final Stream<T> closeables) throws 
IOException {
+        if (closeables != null) {
+            try {
+                close(closeables);
+            } catch (final IOException e) {
+                if (consumer != null) {
+                    consumer.accept(e);
+                }
+            } finally {
+                closeables.close();

Review comment:
       Please, do. And also, add a single sentence to the Javadocs, that 
mentions the fact. (Always good, if the caller is made aware of his/her 
ressponsibilities.)
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to