commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r578494 - in /commons/proper/fileupload/trunk/src: changes/changes.xml java/org/apache/commons/fileupload/FileUploadBase.java java/org/apache/commons/fileupload/MultipartStream.java
Date Sat, 22 Sep 2007 20:45:22 GMT
Author: jochen
Date: Sat Sep 22 13:45:22 2007
New Revision: 578494

URL: http://svn.apache.org/viewvc?rev=578494&view=rev
Log:
A FileSizeLimitExceededException was deferred until the
complete file has been uploaded.
PR: FILEUPLOAD-145

Modified:
    commons/proper/fileupload/trunk/src/changes/changes.xml
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
    commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java

Modified: commons/proper/fileupload/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/changes/changes.xml?rev=578494&r1=578493&r2=578494&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/changes/changes.xml (original)
+++ commons/proper/fileupload/trunk/src/changes/changes.xml Sat Sep 22 13:45:22 2007
@@ -68,6 +68,10 @@
           due-to="Alexander Sova" due-to-email="bird@noir.crocodile.org">
         Short files could cause an unexpected end of the item stream.
       </action>
+      <action dev="jochen" type="fix" issue="FILEUPLOAD-145">
+        A FileSizeLimitExceededException was deferred until the complete
+        file has been uploaded.
+      </action>
     </release>
 
 	<release version="1.2" date="2007-02-13">

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java?rev=578494&r1=578493&r2=578494&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java
Sat Sep 22 13:45:22 2007
@@ -28,6 +28,7 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.fileupload.MultipartStream.ItemInputStream;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.commons.fileupload.servlet.ServletRequestContext;
 import org.apache.commons.fileupload.util.Closeable;
@@ -715,11 +716,13 @@
                 fieldName = pFieldName;
                 contentType = pContentType;
                 formField = pFormField;
-                InputStream istream = multi.newInputStream();
+                final ItemInputStream itemStream = multi.newInputStream();
+                InputStream istream = itemStream;
                 if (fileSizeMax != -1) {
                     istream = new LimitedInputStream(istream, fileSizeMax) {
                         protected void raiseError(long pSizeMax, long pCount)
                                 throws IOException {
+                            itemStream.close(true);
                             FileUploadException e =
                                 new FileSizeLimitExceededException(
                                     "The field " + fieldName

Modified: commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java?rev=578494&r1=578493&r2=578494&view=diff
==============================================================================
--- commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java
(original)
+++ commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java
Sat Sep 22 13:45:22 2007
@@ -897,18 +897,32 @@
          * @throws IOException An I/O error occurred.
          */
         public void close() throws IOException {
+            close(false);
+        }
+
+        /**
+         * Closes the input stream.
+         * @param pCloseUnderlying Whether to close the underlying stream (hard close)
+         * @throws IOException An I/O error occurred.
+         */
+        public void close(boolean pCloseUnderlying) throws IOException {
             if (closed) {
                 return;
             }
-            for (;;) {
-                int av = available();
-                if (av == 0) {
-                    av = makeAvailable();
+            if (pCloseUnderlying) {
+                closed = true;
+                input.close();
+            } else {
+                for (;;) {
+                    int av = available();
                     if (av == 0) {
-                        break;
+                        av = makeAvailable();
+                        if (av == 0) {
+                            break;
+                        }
                     }
+                    skip(av);
                 }
-                skip(av);
             }
             closed = true;
         }



Mime
View raw message