IOUtils chain together IOException for Closeables, add overload
This pull request chains together IOExceptions thrown from closing multiple Closeable instances, which allows the method to attempt to close all of the Closeable instances rather than halting at the first IOException. An overload is added to allow closing multiple Closeable instances and passing the possible resulting IOException to an IOConsumer<IOException>.
-1: This makes no sense to me as the exception are not causaly unrelated and you are forcing them to be. This might be a use case for IOExceptionList.
Hi @garydgregory , good suggestion, IOExceptionList seems like the perfect fit for this. I have revised the code to use this class.
I ended up reworking the underlying so that now the method looks like this
public static void close(final Closeable... closeables) throws IOException {
IOConsumer.forEach(closeables, IOUtils::close);
}
See also forEachIndex which provides slightly different information for compatibility with other call sites.
Hi @wodencafe Thank you for your update. Now I see one new method, without any tests, and not used from anywhere.
- Should the [] be changed to a ... and moved to the last parameter position? I would think so.
- Can the method be used within the code base?
- There are no tests.
Hello @garydgregory , my apologies, I got swamped this weekend and haven't updated this PR with tests. I also agree that the [] should be changed to ... varargs and swapped to be the last parameter, so I will implement this change, and see if there are other places in Commons IO that can take advantage of this new functionality. I will add tests for this today.
Thank you for reviewing the changes, and the contributions and feedback.
Coverage decreased (-0.5%) to 87.329% when pulling 1ccb075f79ec06e763e6b62417d0602c98524749 on wodencafe:IOUtils-closewitherrors into 5300267aa9d13ec0f800b221e3086e835be697be on apache:master.
Hi @garydgregory , I have updated the pull request with the changes you suggested. Thank you!