Repository: commons-io
Updated Branches:
  refs/heads/master d4f28d7ff -> acceb6296


IO-542: FileUtils#readFileToByteArray: optimize reading of files with known 
size (closes #38)


Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/936b820a
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/936b820a
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/936b820a

Branch: refs/heads/master
Commit: 936b820a4e9b9f96661c961bab87e4ec05ca0574
Parents: d4f28d7
Author: Ilmars Poikans <ilm...@delibero.lv>
Authored: Sun Jul 2 16:01:23 2017 +0300
Committer: pascalschumacher <pascalschumac...@gmx.net>
Committed: Sun Jul 2 17:09:47 2017 +0200

----------------------------------------------------------------------
 src/main/java/org/apache/commons/io/FileUtils.java | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-io/blob/936b820a/src/main/java/org/apache/commons/io/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java 
b/src/main/java/org/apache/commons/io/FileUtils.java
index 10f39b9..f03d785 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1849,7 +1849,9 @@ public class FileUtils {
      */
     public static byte[] readFileToByteArray(final File file) throws 
IOException {
         try (InputStream in = openInputStream(file)) {
-            return IOUtils.toByteArray(in); // Do NOT use file.length() - see 
IO-453
+            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(in, fileLength) : 
IOUtils.toByteArray(in);
         }
     }
 

Reply via email to