Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46075
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 27 Oct 2008 22:40:48 +0000 (22:40 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 27 Oct 2008 22:40:48 +0000 (22:40 +0000)
Don't automatically create the ByteArrayOutputStream with the full threshold - we probably won't need it in most cases.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@708361 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java

index 5ba4165..569eb62 100644 (file)
@@ -84,7 +84,14 @@ public class DeferredFileOutputStream
         super(threshold);
         this.outputFile = outputFile;
 
-        memoryOutputStream = new ByteArrayOutputStream(threshold);
+        if (threshold < DefaultFileItemFactory.DEFAULT_SIZE_THRESHOLD) {
+            // Small threshold, use it
+            memoryOutputStream = new ByteArrayOutputStream(threshold);
+        } else {
+            // Large threshold. Use default and array will expand if required
+            memoryOutputStream = new ByteArrayOutputStream(
+                    DefaultFileItemFactory.DEFAULT_SIZE_THRESHOLD);
+        }
         currentOutputStream = memoryOutputStream;
     }