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



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

Review comment:
       Agreed, closing the stream here is making an assumption that this should 
be a terminal operation on the stream, which is a limitation on its usefulness. 
The caller can close the stream on their own when they are finished with it. I 
will update the code.




-- 
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