svn commit: r1821054 - in /ofbiz: branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1821054 - in /ofbiz: branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

jleroux@apache.org
Author: jleroux
Date: Sat Jan 13 09:37:38 2018
New Revision: 1821054

URL: http://svn.apache.org/viewvc?rev=1821054&view=rev
Log:
Fixed: streaming large content cause out of memory exception.
(OFBIZ-10133)

No functional change in trunk
Slightly improves formatting in streamContent() in trunk.

Uses the same code in R16, notably for setting
byte[] buffer = new byte[bufferSize];
that guarantee no issues, and using try-with-ressource

Modified:
    ofbiz/branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java

Modified: ofbiz/branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java?rev=1821054&r1=1821053&r2=1821054&view=diff
==============================================================================
--- ofbiz/branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/branches/release16.11/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java Sat Jan 13 09:37:38 2018
@@ -1064,31 +1064,17 @@ public final class UtilHttp {
         }
 
         // initialize the buffered streams
-
         int bufferSize = EntityUtilProperties.getPropertyAsInteger("content", "stream.buffersize", 8192);
-
-        BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);
-        BufferedInputStream bis = new BufferedInputStream(in, bufferSize);
-
-        byte[] buffer = new byte[length];
+        byte[] buffer = new byte[bufferSize];
         int read = 0;
-        try {
+        try (BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);
+                BufferedInputStream bis = new BufferedInputStream(in, bufferSize)) {
             while ((read = bis.read(buffer, 0, buffer.length)) != -1) {
                 bos.write(buffer, 0, read);
             }
         } catch (IOException e) {
             Debug.logError(e, "Problem reading/writing buffers", module);
-            bis.close();
-            bos.close();
             throw e;
-        } finally {
-            if (bis != null) {
-                bis.close();
-            }
-            if (bos != null) {
-                bos.flush();
-                bos.close();
-            }
         }
     }
 

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java?rev=1821054&r1=1821053&r2=1821054&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilHttp.java Sat Jan 13 09:37:38 2018
@@ -1092,10 +1092,8 @@ public final class UtilHttp {
         int bufferSize = EntityUtilProperties.getPropertyAsInteger("content", "stream.buffersize", 8192);
         byte[] buffer = new byte[bufferSize];
         int read = 0;
-        try (
-                BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);
-                BufferedInputStream bis = new BufferedInputStream(in, bufferSize);
-        ) {
+        try (BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);
+                BufferedInputStream bis = new BufferedInputStream(in, bufferSize)) {
             while ((read = bis.read(buffer, 0, buffer.length)) != -1) {
                 bos.write(buffer, 0, read);
             }