You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/09/15 01:16:20 UTC

[commons-io] branch master updated: Use NIO for internals.

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 f281d13  Use NIO for internals.
f281d13 is described below

commit f281d132aa48091b4a659cf8306a1eec6d130c6b
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Sep 14 21:16:18 2021 -0400

    Use NIO for internals.
---
 src/main/java/org/apache/commons/io/FileUtils.java | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 98ced98..8e1d016 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -2608,11 +2608,8 @@ public class FileUtils {
      * @since 1.1
      */
     public static byte[] readFileToByteArray(final File file) throws IOException {
-        try (InputStream inputStream = openInputStream(file)) {
-            final long fileLength = file.length();
-            // file.length() may return 0 for system-dependent entities, treat 0 as unknown length - see IO-453
-            return fileLength > 0 ? IOUtils.toByteArray(inputStream, fileLength) : IOUtils.toByteArray(inputStream);
-        }
+        Objects.requireNonNull(file, "file");
+        return Files.readAllBytes(file.toPath());
     }
 
     /**