[GitHub] [commons-io] garydgregory commented on a change in pull request #300: IOUtils chain together IOException for Closeables, add overload

2021-11-11 Thread GitBox


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



##
File path: src/main/java/org/apache/commons/io/function/IOConsumer.java
##
@@ -85,13 +150,25 @@
  */
 void accept(T t) throws IOException;
 
+/**
+ * Returns this {@code IOConsumer} wrapped inside of a {@link Consumer}
+ * that throws {@link UncheckedIOException} for any {@link IOException}s
+ * that are thrown by this {@code IOConsumer}.
+ *
+ * @return a {@code Consumer} that wraps this {@code IOConsumer}.
+ * @since 2.12.0
+ */
+default Consumer asConsumer() {
+return wrap(this);

Review comment:
   I do not think we need an extra method that just delegates to an 
existing one. What is the added value? Am I missing something here?

##
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  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  void close(final Stream closeables) 
throws IOExceptionList {
+if (closeables != null) {
+try {
+IOConsumer.forEachIndexed(closeables, IOUtils::close);
+} finally {
+closeables.close();

Review comment:
   This method should not release a resource it did not acquire IMO. 




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [commons-io] garydgregory commented on a change in pull request #300: IOUtils chain together IOException for Closeables, add overload

2021-11-11 Thread GitBox


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



##
File path: src/main/java/org/apache/commons/io/IOUtils.java
##
@@ -414,6 +433,48 @@ public static void close(final Closeable closeable, final 
IOConsumer 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  void close(final 
IOConsumer consumer, final Stream closeables) throws 
IOException {
+if (closeables != null) {
+try {
+close(closeables);
+} catch (final IOException e) {
+if (consumer != null) {
+consumer.accept(e);
+}
+} finally {
+closeables.close();

Review comment:
   This seems wrong to me since this method did not create the stream. The 
caller should manage the stream IMO, it does not matter that a stream also 
happens to be closeable.




-- 
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: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org