You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2017/07/02 15:12:36 UTC

[1/2] commons-io git commit: IO-542: FileUtils#readFileToByteArray: optimize reading of files with known size (closes #38)

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 <il...@delibero.lv>
Authored: Sun Jul 2 16:01:23 2017 +0300
Committer: pascalschumacher <pa...@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);
         }
     }
 


[2/2] commons-io git commit: IO-542: FileUtils#readFileToByteArray: optimize reading of files with known size

Posted by pa...@apache.org.
IO-542: FileUtils#readFileToByteArray: optimize reading of files with known size

add changes.xml entry


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

Branch: refs/heads/master
Commit: acceb62960971477744f6731bbbc06abbabfe4f3
Parents: 936b820
Author: pascalschumacher <pa...@gmx.net>
Authored: Sun Jul 2 17:12:11 2017 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Jul 2 17:12:11 2017 +0200

----------------------------------------------------------------------
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-io/blob/acceb629/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dd97dc6..6350730 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -47,6 +47,9 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
     <!-- The release date is the date RC is cut -->
     <release version="2.6" date="2017-MM-DD" description="New features and bug fixes.">
+      <action issue="IO-542" dev="pschumacher" type="update" due-to="Ilmars Poikans">
+        FileUtils#readFileToByteArray: optimize reading of files with known size
+      </action>
       <action issue="IO-367" dev="pschumacher" type="add" due-to="James Sawle">
         Add convenience methods for copyToDirectory
       </action>