jmeter-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r1487627 - /jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
Date Wed, 29 May 2013 23:15:06 GMT
On 29 May 2013 21:07,  <pmouawad@apache.org> wrote:
> 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

-1

That looks simpler, but requires an extra 4k buffer to be allocated.
Not ideal when the idea is to reduce memory overhead.

> 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