jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1484366 - in /jmeter/trunk: src/core/org/apache/jmeter/reporters/ResultSaver.java src/jorphan/org/apache/jorphan/util/JOrphanUtils.java xdocs/changes.xml
Date Sun, 19 May 2013 23:21:23 GMT
Author: sebb
Date: Sun May 19 23:21:23 2013
New Revision: 1484366

URL: http://svn.apache.org/r1484366
Log:
Download large files avoiding outOfMemory
Add utility method to do chunking and use in ResultSaver
Bugzilla Id: 54990

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java?rev=1484366&r1=1484365&r2=1484366&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/reporters/ResultSaver.java Sun May 19 23:21:23
2013
@@ -186,7 +186,7 @@ public class ResultSaver extends Abstrac
         FileOutputStream pw = null;
         try {
             pw = new FileOutputStream(out);
-            pw.write(s.getResponseData());
+            JOrphanUtils.write(s.getResponseData(), pw); // chunk the output if necessary
         } catch (FileNotFoundException e1) {
             log.error("Error creating sample file for " + s.getSampleLabel(), e1);
         } catch (IOException e1) {

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=1484366&r1=1484365&r2=1484366&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Sun May 19 23:21:23
2013
@@ -21,6 +21,7 @@ package org.apache.jorphan.util;
 import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.ArrayList;
@@ -521,4 +522,27 @@ public final class JOrphanUtils {
     public static boolean isBlank(final String value) {
         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
+     * and the JVM needs to copy the buffer for use by native code.
+     * 
+     * @param data the buffer to be written
+     * @param output the output stream to use
+     * @throws IOException if there is a problem writing the data
+     */
+    // 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;
+        }
+    }
 }
\ No newline at end of file

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1484366&r1=1484365&r2=1484366&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sun May 19 23:21:23 2013
@@ -205,6 +205,7 @@ Webservice (SOAP) Request has been remov
 <li><bugzilla>54834</bugzilla> - Improve Drag &amp; Drop in the jmeter
tree</li>
 <li><bugzilla>54864</bugzilla> - Enable multi selection drag &amp;
drop in the tree without having to start dragging before releasing Shift or Control </li>
 <li><bugzilla>54945</bugzilla> - Add Shutdown Hook to enable trapping kill
or CTRL+C signals</li>
+<li><bugzilla>54990</bugzilla> - Download large files avoiding outOfMemory</li>
 </ul>
 
 <h2>Non-functional changes</h2>



Mime
View raw message