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 f22b426  Use NIO internally to avoid using finalizable FileInputStream.
f22b426 is described below

commit f22b42618d704a09aac21db143bd7ee8d957e13a
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Thu Sep 16 14:30:15 2021 -0400

    Use NIO internally to avoid using finalizable FileInputStream.
---
 src/main/java/org/apache/commons/io/FileUtils.java | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/FileUtils.java 
b/src/main/java/org/apache/commons/io/FileUtils.java
index 1749de5..7a86942 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1061,7 +1061,7 @@ public class FileUtils {
      * @since 2.5
      */
     public static void copyToFile(final InputStream inputStream, final File 
file) throws IOException {
-        try (OutputStream out = openOutputStream(file)) {
+        try (OutputStream out = newOutputStream(file, false)) {
             IOUtils.copy(inputStream, out);
         }
     }
@@ -1088,7 +1088,7 @@ public class FileUtils {
      */
     public static void copyURLToFile(final URL source, final File destination) 
throws IOException {
         try (final InputStream stream = source.openStream()) {
-            copyInputStreamToFile(stream, destination);
+            Files.copy(stream, destination.toPath());
         }
     }
 
@@ -1305,11 +1305,7 @@ public class FileUtils {
     public static boolean directoryContains(final File directory, final File 
child) throws IOException {
         requireDirectoryExists(directory, "directory");
 
-        if (child == null) {
-            return false;
-        }
-
-        if (!directory.exists() || !child.exists()) {
+        if (child == null || !directory.exists() || !child.exists()) {
             return false;
         }
 
@@ -3158,7 +3154,7 @@ public class FileUtils {
     public static void touch(final File file) throws IOException {
         Objects.requireNonNull(file, "file");
         if (!file.exists()) {
-            openOutputStream(file).close();
+            newOutputStream(file, false).close();
         }
         PathUtils.setLastModifiedTime(file.toPath());
     }

Reply via email to