org.apache.commons.io.FileUtils.copyURLToFile(*) open but do
not close streams.
MODIFY
src/changes/changes.xml
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.">

MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
@@ -1022,7 +1022,9 @@ public static void copyToFile(final InputStream source, final File destination)
* @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);
+ }
}
/**
@@ -1050,7 +1052,9 @@ public static void copyURLToFile(final URL source, final File destination,
final URLConnection connection = source.openConnection();
connection.setConnectTimeout(connectionTimeout);
connection.setReadTimeout(readTimeout);
- copyInputStreamToFile(connection.getInputStream(), destination);
+ try (final InputStream stream = connection.getInputStream()) {
+ copyInputStreamToFile(stream, destination);
+ }
}
/**

[IO-664] org.apache.commons.io.FileUtils.copyURLToFile(*) open but do
not close streams.