jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1487627 - /jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
Date Wed, 29 May 2013 20:07:21 GMT
Author: pmouawad
Date: Wed May 29 20:07:20 2013
New Revision: 1487627

URL: http://svn.apache.org/r1487627
Log:
Bug 54990 - Download large files avoiding outOfMemory
Use method from commons-io
Bugzilla Id: 54990

Modified:
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java

Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java?rev=1487627&r1=1487626&r2=1487627&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Wed May 29 20:07:20
2013
@@ -18,6 +18,7 @@
 
 package org.apache.jorphan.util;
 
+import java.io.ByteArrayInputStream;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
@@ -29,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.StringTokenizer;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 
 /**
@@ -523,8 +525,6 @@ public final class JOrphanUtils {
         return StringUtils.isBlank(value);
     }
 
-    private static final int DEFAULT_CHUNK_SIZE = 4096;
-
     /**
      * Write data to an output stream in chunks with a maximum size of 4K.
      * This is to avoid OutOfMemory issues if the data buffer is very large
@@ -536,13 +536,6 @@ public final class JOrphanUtils {
      */
     // Bugzilla 54990
     public static void write(byte[] data, OutputStream output) throws IOException {
-        int bytes = data.length;
-        int offset = 0;
-        while(bytes > 0) {
-            int chunk = Math.min(bytes, DEFAULT_CHUNK_SIZE);
-            output.write(data, offset, chunk);
-            bytes -= chunk;
-            offset += chunk;
-        }
+        IOUtils.copyLarge(new ByteArrayInputStream(data), output);
     }
 }
\ No newline at end of file



Mime
View raw message