This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new 227c613 [IO-664] org.apache.commons.io.FileUtils.copyURLToFile(*)
open but do not close streams.
227c613 is described below
commit 227c61391448559e21e7cee6833c75980595e9e5
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Apr 12 12:00:04 2020 -0400
[IO-664] org.apache.commons.io.FileUtils.copyURLToFile(*) open but do
not close streams.
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/io/FileUtils.java | 10 +++++++---
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c0d891c..6ac8b74 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -204,6 +204,9 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="IO-662" dev="ggregory" type="add" due-to="Adam Retter,
Gary Gregory">
Refactor ByteArrayOutputStream into synchronized and unsynchronized
versions #108.
</action>
+ <action issue="IO-664" dev="ggregory" type="fix" due-to="Gary Gregory">
+ org.apache.commons.io.FileUtils.copyURLToFile(*) open but do not
close streams.
+ </action>
</release>
<release version="2.6" date="2017-10-15" description="Java 7 required,
Java 9 supported.">
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java
b/src/main/java/org/apache/commons/io/FileUtils.java
index 5d59350..e5b1ee8 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1022,7 +1022,9 @@ public class FileUtils {
* @throws IOException if an IO error occurs during copying
*/
public static void copyURLToFile(final URL source, final File destination)
throws IOException {
- copyInputStreamToFile(source.openStream(), destination);
+ try (final InputStream stream = source.openStream()) {
+ copyInputStreamToFile(stream, destination);
+ }
}
/**
@@ -1046,11 +1048,13 @@ public class FileUtils {
* @since 2.0
*/
public static void copyURLToFile(final URL source, final File destination,
- final int connectionTimeout, final int
readTimeout) throws IOException {
+ final int connectionTimeout, final int readTimeout) throws IOException
{
final URLConnection connection = source.openConnection();
connection.setConnectTimeout(connectionTimeout);
connection.setReadTimeout(readTimeout);
- copyInputStreamToFile(connection.getInputStream(), destination);
+ try (final InputStream stream = connection.getInputStream()) {
+ copyInputStreamToFile(stream, destination);
+ }
}
/**