"Applied fix from trunk for revision: 1821036 "

------------------------------------------------------------------------
r1821036 | jleroux | 2018-01-12 22:59:22 +0100 (ven., 12 janv. 2018) | 11 lines

Fixed: streaming large content cause out of memory exception.
(OFBIZ-10133)

When ofbiz streams a large content (eg. video file), get out of memory exception.

To reproduce the issue see the Jira

jleroux: I just removed final for bufferSize, I see no needs for that local
variable

Thanks: Wai for the patch Michael for the discussion
------------------------------------------------------------------------


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/branches/release17.12@1821037 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2018-01-12 22:00:22 +00:00
parent a740eb687a
commit ce7094e6e6
4 changed files with 11 additions and 8 deletions
@@ -56,6 +56,7 @@ import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
import org.apache.ofbiz.widget.renderer.VisualTheme;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
@@ -1086,8 +1087,6 @@ public final class UtilHttp {
* @throws IOException
*/
public static void streamContent(OutputStream out, InputStream in, int length) throws IOException {
int bufferSize = 512; // same as the default buffer size; change as needed
// make sure we have something to write to
if (out == null) {
throw new IOException("Attempt to write to null output stream");
@@ -1104,8 +1103,8 @@ public final class UtilHttp {
}
// initialize the buffered streams
byte[] buffer = new byte[length];
int bufferSize = EntityUtilProperties.getPropertyAsInteger("content", "stream.buffersize", 8192);
byte[] buffer = new byte[bufferSize];
int read = 0;
try (
BufferedOutputStream bos = new BufferedOutputStream(out, bufferSize);