Author: sebb
Date: Thu Mar 22 21:23:42 2012
New Revision: 1304074

URL: http://svn.apache.org/viewvc?rev=1304074&view=rev
Log:
Calculate buffer lengthe once

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java

Modified: 
commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java?rev=1304074&r1=1304073&r2=1304074&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java 
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/IOUtils.java 
Thu Mar 22 21:23:42 2012
@@ -1486,9 +1486,10 @@ public class IOUtils {
         if (length == 0) {
             return 0;
         }
-        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
-        int bytesToRead = buffer.length;
-        if (length > 0 && length < buffer.length) {
+        final byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
+        final int bufferLength = buffer.length;
+        int bytesToRead = bufferLength;
+        if (length > 0 && length < bufferLength) {
             bytesToRead = (int) length;
         }
         int read;
@@ -1498,7 +1499,7 @@ public class IOUtils {
             totalRead += read;
             if (length > 0) { // only adjust length if not reading to the end
                 // Note the cast must work because buffer.length is an integer
-                bytesToRead = (int) Math.min(length - totalRead, 
buffer.length);
+                bytesToRead = (int) Math.min(length - totalRead, bufferLength);
             }
         }
         return totalRead;


Reply via email to