PR: FILEUPLOAD-300

Moved exception classes to impl package.
diff --git a/src/main/java/org/apache/commons/fileupload2/FileItemIterator.java b/src/main/java/org/apache/commons/fileupload2/FileItemIterator.java
index b56706d..7b39f35 100644
--- a/src/main/java/org/apache/commons/fileupload2/FileItemIterator.java
+++ b/src/main/java/org/apache/commons/fileupload2/FileItemIterator.java
@@ -19,7 +19,8 @@
 import java.io.IOException;

 import java.util.List;

 

-import org.apache.commons.fileupload2.FileUploadBase.FileSizeLimitExceededException;

+import org.apache.commons.fileupload2.impl.FileSizeLimitExceededException;

+import org.apache.commons.fileupload2.impl.SizeLimitExceededException;

 

 /**

  * An iterator, as returned by

diff --git a/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java b/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
index 4ba37ac..5b03531 100644
--- a/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
+++ b/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
@@ -31,6 +31,8 @@
 
 import org.apache.commons.fileupload2.impl.FileItemIteratorImpl;
 import org.apache.commons.fileupload2.impl.FileItemStreamImpl;
+import org.apache.commons.fileupload2.impl.FileUploadIOException;
+import org.apache.commons.fileupload2.impl.IOFileUploadException;
 import org.apache.commons.fileupload2.servlet.ServletFileUpload;
 import org.apache.commons.fileupload2.servlet.ServletRequestContext;
 import org.apache.commons.fileupload2.util.FileItemHeadersImpl;
@@ -699,345 +701,6 @@
     }
 
     /**
-     * This exception is thrown for hiding an inner
-     * {@link FileUploadException} in an {@link IOException}.
-     */
-    public static class FileUploadIOException extends IOException {
-
-        /**
-         * The exceptions UID, for serializing an instance.
-         */
-        private static final long serialVersionUID = -7047616958165584154L;
-
-        /**
-         * The exceptions cause; we overwrite the parent
-         * classes field, which is available since Java
-         * 1.4 only.
-         */
-        private final FileUploadException cause;
-
-        /**
-         * Creates a <code>FileUploadIOException</code> with the
-         * given cause.
-         *
-         * @param pCause The exceptions cause, if any, or null.
-         */
-        public FileUploadIOException(FileUploadException pCause) {
-            // We're not doing super(pCause) cause of 1.3 compatibility.
-            cause = pCause;
-        }
-
-        /**
-         * Returns the exceptions cause.
-         *
-         * @return The exceptions cause, if any, or null.
-         */
-        @Override
-        public Throwable getCause() {
-            return cause;
-        }
-
-    }
-
-    /**
-     * Thrown to indicate that the request is not a multipart request.
-     */
-    public static class InvalidContentTypeException
-            extends FileUploadException {
-
-        /**
-         * The exceptions UID, for serializing an instance.
-         */
-        private static final long serialVersionUID = -9073026332015646668L;
-
-        /**
-         * Constructs a <code>InvalidContentTypeException</code> with no
-         * detail message.
-         */
-        public InvalidContentTypeException() {
-            super();
-        }
-
-        /**
-         * Constructs an <code>InvalidContentTypeException</code> with
-         * the specified detail message.
-         *
-         * @param message The detail message.
-         */
-        public InvalidContentTypeException(String message) {
-            super(message);
-        }
-
-        /**
-         * Constructs an <code>InvalidContentTypeException</code> with
-         * the specified detail message and cause.
-         *
-         * @param msg The detail message.
-         * @param cause the original cause
-         *
-         * @since 1.3.1
-         */
-        public InvalidContentTypeException(String msg, Throwable cause) {
-            super(msg, cause);
-        }
-    }
-
-    /**
-     * Thrown to indicate an IOException.
-     */
-    public static class IOFileUploadException extends FileUploadException {
-
-        /**
-         * The exceptions UID, for serializing an instance.
-         */
-        private static final long serialVersionUID = 1749796615868477269L;
-
-        /**
-         * The exceptions cause; we overwrite the parent
-         * classes field, which is available since Java
-         * 1.4 only.
-         */
-        private final IOException cause;
-
-        /**
-         * Creates a new instance with the given cause.
-         *
-         * @param pMsg The detail message.
-         * @param pException The exceptions cause.
-         */
-        public IOFileUploadException(String pMsg, IOException pException) {
-            super(pMsg);
-            cause = pException;
-        }
-
-        /**
-         * Returns the exceptions cause.
-         *
-         * @return The exceptions cause, if any, or null.
-         */
-        @Override
-        public Throwable getCause() {
-            return cause;
-        }
-
-    }
-
-    /**
-     * This exception is thrown, if a requests permitted size
-     * is exceeded.
-     */
-    protected abstract static class SizeException extends FileUploadException {
-
-        /**
-         * Serial version UID, being used, if serialized.
-         */
-        private static final long serialVersionUID = -8776225574705254126L;
-
-        /**
-         * The actual size of the request.
-         */
-        private final long actual;
-
-        /**
-         * The maximum permitted size of the request.
-         */
-        private final long permitted;
-
-        /**
-         * Creates a new instance.
-         *
-         * @param message The detail message.
-         * @param actual The actual number of bytes in the request.
-         * @param permitted The requests size limit, in bytes.
-         */
-        protected SizeException(String message, long actual, long permitted) {
-            super(message);
-            this.actual = actual;
-            this.permitted = permitted;
-        }
-
-        /**
-         * Retrieves the actual size of the request.
-         *
-         * @return The actual size of the request.
-         * @since 1.3
-         */
-        public long getActualSize() {
-            return actual;
-        }
-
-        /**
-         * Retrieves the permitted size of the request.
-         *
-         * @return The permitted size of the request.
-         * @since 1.3
-         */
-        public long getPermittedSize() {
-            return permitted;
-        }
-
-    }
-
-    /**
-     * Thrown to indicate that the request size is not specified. In other
-     * words, it is thrown, if the content-length header is missing or
-     * contains the value -1.
-     *
-     * @deprecated 1.2 As of commons-fileupload 1.2, the presence of a
-     *   content-length header is no longer required.
-     */
-    @Deprecated
-    public static class UnknownSizeException
-        extends FileUploadException {
-
-        /**
-         * The exceptions UID, for serializing an instance.
-         */
-        private static final long serialVersionUID = 7062279004812015273L;
-
-        /**
-         * Constructs a <code>UnknownSizeException</code> with no
-         * detail message.
-         */
-        public UnknownSizeException() {
-            super();
-        }
-
-        /**
-         * Constructs an <code>UnknownSizeException</code> with
-         * the specified detail message.
-         *
-         * @param message The detail message.
-         */
-        public UnknownSizeException(String message) {
-            super(message);
-        }
-
-    }
-
-    /**
-     * Thrown to indicate that the request size exceeds the configured maximum.
-     */
-    public static class SizeLimitExceededException
-            extends SizeException {
-
-        /**
-         * The exceptions UID, for serializing an instance.
-         */
-        private static final long serialVersionUID = -2474893167098052828L;
-
-        /**
-         * @deprecated 1.2 Replaced by
-         * {@link #SizeLimitExceededException(String, long, long)}
-         */
-        @Deprecated
-        public SizeLimitExceededException() {
-            this(null, 0, 0);
-        }
-
-        /**
-         * @deprecated 1.2 Replaced by
-         * {@link #SizeLimitExceededException(String, long, long)}
-         * @param message The exceptions detail message.
-         */
-        @Deprecated
-        public SizeLimitExceededException(String message) {
-            this(message, 0, 0);
-        }
-
-        /**
-         * Constructs a <code>SizeExceededException</code> with
-         * the specified detail message, and actual and permitted sizes.
-         *
-         * @param message   The detail message.
-         * @param actual    The actual request size.
-         * @param permitted The maximum permitted request size.
-         */
-        public SizeLimitExceededException(String message, long actual,
-                long permitted) {
-            super(message, actual, permitted);
-        }
-
-    }
-
-    /**
-     * Thrown to indicate that A files size exceeds the configured maximum.
-     */
-    public static class FileSizeLimitExceededException
-            extends SizeException {
-
-        /**
-         * The exceptions UID, for serializing an instance.
-         */
-        private static final long serialVersionUID = 8150776562029630058L;
-
-        /**
-         * File name of the item, which caused the exception.
-         */
-        private String fileName;
-
-        /**
-         * Field name of the item, which caused the exception.
-         */
-        private String fieldName;
-
-        /**
-         * Constructs a <code>SizeExceededException</code> with
-         * the specified detail message, and actual and permitted sizes.
-         *
-         * @param message   The detail message.
-         * @param actual    The actual request size.
-         * @param permitted The maximum permitted request size.
-         */
-        public FileSizeLimitExceededException(String message, long actual,
-                long permitted) {
-            super(message, actual, permitted);
-        }
-
-        /**
-         * Returns the file name of the item, which caused the
-         * exception.
-         *
-         * @return File name, if known, or null.
-         */
-        public String getFileName() {
-            return fileName;
-        }
-
-        /**
-         * Sets the file name of the item, which caused the
-         * exception.
-         *
-         * @param pFileName the file name of the item, which caused the exception.
-         */
-        public void setFileName(String pFileName) {
-            fileName = pFileName;
-        }
-
-        /**
-         * Returns the field name of the item, which caused the
-         * exception.
-         *
-         * @return Field name, if known, or null.
-         */
-        public String getFieldName() {
-            return fieldName;
-        }
-
-        /**
-         * Sets the field name of the item, which caused the
-         * exception.
-         *
-         * @param pFieldName the field name of the item,
-         *        which caused the exception.
-         */
-        public void setFieldName(String pFieldName) {
-            fieldName = pFieldName;
-        }
-
-    }
-
-    /**
      * Returns the progress listener.
      *
      * @return The progress listener, if any, or null.
diff --git a/src/main/java/org/apache/commons/fileupload2/MultipartStream.java b/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
index ff36d9d..4d14b01 100644
--- a/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
+++ b/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
@@ -24,7 +24,7 @@
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 
-import org.apache.commons.fileupload2.FileUploadBase.FileUploadIOException;
+import org.apache.commons.fileupload2.impl.FileUploadIOException;
 import org.apache.commons.fileupload2.util.Closeable;
 import org.apache.commons.fileupload2.util.Streams;
 
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java
index 2f0396e..1fc7185 100644
--- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemIteratorImpl.java
@@ -35,9 +35,6 @@
 import org.apache.commons.fileupload2.ProgressListener;

 import org.apache.commons.fileupload2.RequestContext;

 import org.apache.commons.fileupload2.UploadContext;

-import org.apache.commons.fileupload2.FileUploadBase.FileUploadIOException;

-import org.apache.commons.fileupload2.FileUploadBase.InvalidContentTypeException;

-import org.apache.commons.fileupload2.FileUploadBase.SizeLimitExceededException;

 import org.apache.commons.fileupload2.util.LimitedInputStream;

 import org.apache.commons.io.IOUtils;

 

diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
index 9a40a25..a4db26b 100644
--- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
@@ -23,11 +23,8 @@
 

 import org.apache.commons.fileupload2.FileItemHeaders;

 import org.apache.commons.fileupload2.FileItemStream;

-import org.apache.commons.fileupload2.FileUploadBase;

 import org.apache.commons.fileupload2.FileUploadException;

 import org.apache.commons.fileupload2.InvalidFileNameException;

-import org.apache.commons.fileupload2.FileUploadBase.FileSizeLimitExceededException;

-import org.apache.commons.fileupload2.FileUploadBase.FileUploadIOException;

 import org.apache.commons.fileupload2.MultipartStream.ItemInputStream;

 import org.apache.commons.fileupload2.util.Closeable;

 import org.apache.commons.fileupload2.util.LimitedInputStream;

@@ -97,7 +94,7 @@
         if (fileSizeMax != -1) { // Check if limit is already exceeded

             if (pContentLength != -1

                     && pContentLength > fileSizeMax) {

-                FileUploadBase.FileSizeLimitExceededException e =

+                FileSizeLimitExceededException e =

                         new FileSizeLimitExceededException(

                                 format("The field %s exceeds its maximum permitted size of %s bytes.",

                                         fieldName, Long.valueOf(fileSizeMax)),

@@ -116,7 +113,7 @@
                 protected void raiseError(long pSizeMax, long pCount)

                         throws IOException {

                     itemStream.close(true);

-                    FileUploadBase.FileSizeLimitExceededException e =

+                    FileSizeLimitExceededException e =

                         new FileSizeLimitExceededException(

                             format("The field %s exceeds its maximum permitted size of %s bytes.",

                                    fieldName, Long.valueOf(pSizeMax)),

diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileSizeLimitExceededException.java b/src/main/java/org/apache/commons/fileupload2/impl/FileSizeLimitExceededException.java
new file mode 100644
index 0000000..096c03c
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileSizeLimitExceededException.java
@@ -0,0 +1,94 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+/**

+ * Thrown to indicate that A files size exceeds the configured maximum.

+ */

+public class FileSizeLimitExceededException

+        extends SizeException {

+

+    /**

+     * The exceptions UID, for serializing an instance.

+     */

+    private static final long serialVersionUID = 8150776562029630058L;

+

+    /**

+     * File name of the item, which caused the exception.

+     */

+    private String fileName;

+

+    /**

+     * Field name of the item, which caused the exception.

+     */

+    private String fieldName;

+

+    /**

+     * Constructs a <code>SizeExceededException</code> with

+     * the specified detail message, and actual and permitted sizes.

+     *

+     * @param message   The detail message.

+     * @param actual    The actual request size.

+     * @param permitted The maximum permitted request size.

+     */

+    public FileSizeLimitExceededException(String message, long actual,

+            long permitted) {

+        super(message, actual, permitted);

+    }

+

+    /**

+     * Returns the file name of the item, which caused the

+     * exception.

+     *

+     * @return File name, if known, or null.

+     */

+    public String getFileName() {

+        return fileName;

+    }

+

+    /**

+     * Sets the file name of the item, which caused the

+     * exception.

+     *

+     * @param pFileName the file name of the item, which caused the exception.

+     */

+    public void setFileName(String pFileName) {

+        fileName = pFileName;

+    }

+

+    /**

+     * Returns the field name of the item, which caused the

+     * exception.

+     *

+     * @return Field name, if known, or null.

+     */

+    public String getFieldName() {

+        return fieldName;

+    }

+

+    /**

+     * Sets the field name of the item, which caused the

+     * exception.

+     *

+     * @param pFieldName the field name of the item,

+     *        which caused the exception.

+     */

+    public void setFieldName(String pFieldName) {

+        fieldName = pFieldName;

+    }

+

+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileUploadIOException.java b/src/main/java/org/apache/commons/fileupload2/impl/FileUploadIOException.java
new file mode 100644
index 0000000..e1b214e
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileUploadIOException.java
@@ -0,0 +1,62 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+import java.io.IOException;

+

+import org.apache.commons.fileupload2.FileUploadException;

+

+/**

+ * This exception is thrown for hiding an inner

+ * {@link FileUploadException} in an {@link IOException}.

+ */

+public class FileUploadIOException extends IOException {

+

+    /**

+     * The exceptions UID, for serializing an instance.

+     */

+    private static final long serialVersionUID = -7047616958165584154L;

+

+    /**

+     * The exceptions cause; we overwrite the parent

+     * classes field, which is available since Java

+     * 1.4 only.

+     */

+    private final FileUploadException cause;

+

+    /**

+     * Creates a <code>FileUploadIOException</code> with the

+     * given cause.

+     *

+     * @param pCause The exceptions cause, if any, or null.

+     */

+    public FileUploadIOException(FileUploadException pCause) {

+        // We're not doing super(pCause) cause of 1.3 compatibility.

+        cause = pCause;

+    }

+

+    /**

+     * Returns the exceptions cause.

+     *

+     * @return The exceptions cause, if any, or null.

+     */

+    @Override

+    public Throwable getCause() {

+        return cause;

+    }

+

+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/IOFileUploadException.java b/src/main/java/org/apache/commons/fileupload2/impl/IOFileUploadException.java
new file mode 100644
index 0000000..de7b44d
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/IOFileUploadException.java
@@ -0,0 +1,61 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+import java.io.IOException;

+

+import org.apache.commons.fileupload2.FileUploadException;

+

+/**

+ * Thrown to indicate an IOException.

+ */

+public class IOFileUploadException extends FileUploadException {

+

+    /**

+     * The exceptions UID, for serializing an instance.

+     */

+    private static final long serialVersionUID = 1749796615868477269L;

+

+    /**

+     * The exceptions cause; we overwrite the parent

+     * classes field, which is available since Java

+     * 1.4 only.

+     */

+    private final IOException cause;

+

+    /**

+     * Creates a new instance with the given cause.

+     *

+     * @param pMsg The detail message.

+     * @param pException The exceptions cause.

+     */

+    public IOFileUploadException(String pMsg, IOException pException) {

+        super(pMsg);

+        cause = pException;

+    }

+

+    /**

+     * Returns the exceptions cause.

+     *

+     * @return The exceptions cause, if any, or null.

+     */

+    @Override

+    public Throwable getCause() {

+        return cause;

+    }

+

+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/InvalidContentTypeException.java b/src/main/java/org/apache/commons/fileupload2/impl/InvalidContentTypeException.java
new file mode 100644
index 0000000..e76f311
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/InvalidContentTypeException.java
@@ -0,0 +1,62 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+import org.apache.commons.fileupload2.FileUploadException;

+

+/**

+ * Thrown to indicate that the request is not a multipart request.

+ */

+public class InvalidContentTypeException

+        extends FileUploadException {

+

+    /**

+     * The exceptions UID, for serializing an instance.

+     */

+    private static final long serialVersionUID = -9073026332015646668L;

+

+    /**

+     * Constructs a <code>InvalidContentTypeException</code> with no

+     * detail message.

+     */

+    public InvalidContentTypeException() {

+        super();

+    }

+

+    /**

+     * Constructs an <code>InvalidContentTypeException</code> with

+     * the specified detail message.

+     *

+     * @param message The detail message.

+     */

+    public InvalidContentTypeException(String message) {

+        super(message);

+    }

+

+    /**

+     * Constructs an <code>InvalidContentTypeException</code> with

+     * the specified detail message and cause.

+     *

+     * @param msg The detail message.

+     * @param cause the original cause

+     *

+     * @since 1.3.1

+     */

+    public InvalidContentTypeException(String msg, Throwable cause) {

+        super(msg, cause);

+    }

+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/SizeException.java b/src/main/java/org/apache/commons/fileupload2/impl/SizeException.java
new file mode 100644
index 0000000..d030c30
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/SizeException.java
@@ -0,0 +1,75 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+import org.apache.commons.fileupload2.FileUploadException;

+

+/**

+ * This exception is thrown, if a requests permitted size

+ * is exceeded.

+ */

+abstract class SizeException extends FileUploadException {

+

+    /**

+     * Serial version UID, being used, if serialized.

+     */

+    private static final long serialVersionUID = -8776225574705254126L;

+

+    /**

+     * The actual size of the request.

+     */

+    private final long actual;

+

+    /**

+     * The maximum permitted size of the request.

+     */

+    private final long permitted;

+

+    /**

+     * Creates a new instance.

+     *

+     * @param message The detail message.

+     * @param actual The actual number of bytes in the request.

+     * @param permitted The requests size limit, in bytes.

+     */

+    protected SizeException(String message, long actual, long permitted) {

+        super(message);

+        this.actual = actual;

+        this.permitted = permitted;

+    }

+

+    /**

+     * Retrieves the actual size of the request.

+     *

+     * @return The actual size of the request.

+     * @since 1.3

+     */

+    public long getActualSize() {

+        return actual;

+    }

+

+    /**

+     * Retrieves the permitted size of the request.

+     *

+     * @return The permitted size of the request.

+     * @since 1.3

+     */

+    public long getPermittedSize() {

+        return permitted;

+    }

+

+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/SizeLimitExceededException.java b/src/main/java/org/apache/commons/fileupload2/impl/SizeLimitExceededException.java
new file mode 100644
index 0000000..0b34fae
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/SizeLimitExceededException.java
@@ -0,0 +1,43 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+/**

+ * Thrown to indicate that the request size exceeds the configured maximum.

+ */

+public class SizeLimitExceededException

+        extends SizeException {

+

+    /**

+     * The exceptions UID, for serializing an instance.

+     */

+    private static final long serialVersionUID = -2474893167098052828L;

+

+    /**

+     * Constructs a <code>SizeExceededException</code> with

+     * the specified detail message, and actual and permitted sizes.

+     *

+     * @param message   The detail message.

+     * @param actual    The actual request size.

+     * @param permitted The maximum permitted request size.

+     */

+    public SizeLimitExceededException(String message, long actual,

+            long permitted) {

+        super(message, actual, permitted);

+    }

+

+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/UnknownSizeException.java b/src/main/java/org/apache/commons/fileupload2/impl/UnknownSizeException.java
new file mode 100644
index 0000000..f4068df
--- /dev/null
+++ b/src/main/java/org/apache/commons/fileupload2/impl/UnknownSizeException.java
@@ -0,0 +1,56 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2.impl;

+

+import org.apache.commons.fileupload2.FileUploadException;

+

+/**

+ * Thrown to indicate that the request size is not specified. In other

+ * words, it is thrown, if the content-length header is missing or

+ * contains the value -1.

+ *

+ * @deprecated 1.2 As of commons-fileupload 1.2, the presence of a

+ *   content-length header is no longer required.

+ */

+@Deprecated

+public class UnknownSizeException

+    extends FileUploadException {

+

+    /**

+     * The exceptions UID, for serializing an instance.

+     */

+    private static final long serialVersionUID = 7062279004812015273L;

+

+    /**

+     * Constructs a <code>UnknownSizeException</code> with no

+     * detail message.

+     */

+    public UnknownSizeException() {

+        super();

+    }

+

+    /**

+     * Constructs an <code>UnknownSizeException</code> with

+     * the specified detail message.

+     *

+     * @param message The detail message.

+     */

+    public UnknownSizeException(String message) {

+        super(message);

+    }

+

+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java b/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java
index fad393c..19ce621 100644
--- a/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java
@@ -26,6 +26,7 @@
 import org.apache.commons.fileupload2.DiskFileUpload;
 import org.apache.commons.fileupload2.FileUploadException;
 import org.apache.commons.fileupload2.disk.DiskFileItem;
+import org.apache.commons.fileupload2.impl.InvalidContentTypeException;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -63,7 +64,7 @@
         try {
             upload.parseRequest(req);
             fail("testWithNullContentType: expected exception was not thrown");
-        } catch (DiskFileUpload.InvalidContentTypeException expected) {
+        } catch (InvalidContentTypeException expected) {
             // this exception is expected
         } catch (FileUploadException unexpected) {
             fail("testWithNullContentType: unexpected exception was thrown");
diff --git a/src/test/java/org/apache/commons/fileupload2/SizesTest.java b/src/test/java/org/apache/commons/fileupload2/SizesTest.java
index ab1388b..9f2308d 100644
--- a/src/test/java/org/apache/commons/fileupload2/SizesTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/SizesTest.java
@@ -1,291 +1,291 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.fileupload2.FileItem;
-import org.apache.commons.fileupload2.FileItemIterator;
-import org.apache.commons.fileupload2.FileItemStream;
-import org.apache.commons.fileupload2.FileUploadBase;
-import org.apache.commons.fileupload2.FileUploadException;
-import org.apache.commons.fileupload2.FileUploadBase.FileUploadIOException;
-import org.apache.commons.fileupload2.FileUploadBase.SizeException;
-import org.apache.commons.fileupload2.disk.DiskFileItemFactory;
-import org.apache.commons.fileupload2.servlet.ServletFileUpload;
-import org.apache.commons.fileupload2.util.Streams;
-import org.junit.Test;
-
-/**
- * Unit test for items with varying sizes.
- */
-public class SizesTest {
-
-    /**
-     * Runs a test with varying file sizes.
-     */
-    @Test
-    public void testFileUpload()
-            throws IOException, FileUploadException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        int add = 16;
-        int num = 0;
-        for (int i = 0;  i < 16384;  i += add) {
-            if (++add == 32) {
-                add = 16;
-            }
-            String header = "-----1234\r\n"
-                + "Content-Disposition: form-data; name=\"field" + (num++) + "\"\r\n"
-                + "\r\n";
-            baos.write(header.getBytes("US-ASCII"));
-            for (int j = 0;  j < i;  j++) {
-                baos.write((byte) j);
-            }
-            baos.write("\r\n".getBytes("US-ASCII"));
-        }
-        baos.write("-----1234--\r\n".getBytes("US-ASCII"));
-
-        List<FileItem> fileItems =
-                Util.parseUpload(new ServletFileUpload(new DiskFileItemFactory()), baos.toByteArray());
-        Iterator<FileItem> fileIter = fileItems.iterator();
-        add = 16;
-        num = 0;
-        for (int i = 0;  i < 16384;  i += add) {
-            if (++add == 32) {
-                add = 16;
-            }
-            FileItem item = fileIter.next();
-            assertEquals("field" + (num++), item.getFieldName());
-            byte[] bytes = item.get();
-            assertEquals(i, bytes.length);
-            for (int j = 0;  j < i;  j++) {
-                assertEquals((byte) j, bytes[j]);
-            }
-        }
-        assertTrue(!fileIter.hasNext());
-    }
-
-    /** Checks, whether limiting the file size works.
-     */
-    @Test
-    public void testFileSizeLimit()
-            throws IOException, FileUploadException {
-        final String request =
-            "-----1234\r\n" +
-            "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
-            "Content-Type: text/whatever\r\n" +
-            "\r\n" +
-            "This is the content of the file\n" +
-            "\r\n" +
-            "-----1234--\r\n";
-
-        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(-1);
-        HttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        List<FileItem> fileItems = upload.parseRequest(req);
-        assertEquals(1, fileItems.size());
-        FileItem item = fileItems.get(0);
-        assertEquals("This is the content of the file\n", new String(item.get()));
-
-        upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(40);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        fileItems = upload.parseRequest(req);
-        assertEquals(1, fileItems.size());
-        item = fileItems.get(0);
-        assertEquals("This is the content of the file\n", new String(item.get()));
-
-        upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(30);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        try {
-            upload.parseRequest(req);
-            fail("Expected exception.");
-        } catch (FileUploadBase.FileSizeLimitExceededException e) {
-            assertEquals(30, e.getPermittedSize());
-        }
-    }
-
-    /** Checks, whether a faked Content-Length header is detected.
-     */
-    @Test
-    public void testFileSizeLimitWithFakedContentLength()
-            throws IOException, FileUploadException {
-        final String request =
-            "-----1234\r\n" +
-            "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +
-            "Content-Type: text/whatever\r\n" +
-            "Content-Length: 10\r\n" +
-            "\r\n" +
-            "This is the content of the file\n" +
-            "\r\n" +
-            "-----1234--\r\n";
-
-        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(-1);
-        HttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        List<FileItem> fileItems = upload.parseRequest(req);
-        assertEquals(1, fileItems.size());
-        FileItem item = fileItems.get(0);
-        assertEquals("This is the content of the file\n", new String(item.get()));
-
-        upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(40);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        fileItems = upload.parseRequest(req);
-        assertEquals(1, fileItems.size());
-        item = fileItems.get(0);
-        assertEquals("This is the content of the file\n", new String(item.get()));
-
-        // provided Content-Length is larger than the FileSizeMax -> handled by ctor
-        upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(5);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        try {
-            upload.parseRequest(req);
-            fail("Expected exception.");
-        } catch (FileUploadBase.FileSizeLimitExceededException e) {
-            assertEquals(5, e.getPermittedSize());
-        }
-
-        // provided Content-Length is wrong, actual content is larger -> handled by LimitedInputStream
-        upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(15);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        try {
-            upload.parseRequest(req);
-            fail("Expected exception.");
-        } catch (FileUploadBase.FileSizeLimitExceededException e) {
-            assertEquals(15, e.getPermittedSize());
-        }
-    }
-
-    /** Checks, whether the maxSize works.
-     */
-    @Test
-    public void testMaxSizeLimit()
-            throws IOException, FileUploadException {
-        final String request =
-            "-----1234\r\n" +
-            "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" +
-            "Content-Type: text/whatever\r\n" +
-            "Content-Length: 10\r\n" +
-            "\r\n" +
-            "This is the content of the file\n" +
-            "\r\n" +
-            "-----1234\r\n" +
-            "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.tab\"\r\n" +
-            "Content-Type: text/whatever\r\n" +
-            "\r\n" +
-            "This is the content of the file\n" +
-            "\r\n" +
-            "-----1234--\r\n";
-
-        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(-1);
-        upload.setSizeMax(200);
-
-        MockHttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        try {
-            upload.parseRequest(req);
-            fail("Expected exception.");
-        } catch (FileUploadBase.SizeLimitExceededException e) {
-            assertEquals(200, e.getPermittedSize());
-        }
-    }
-
-    @Test
-    public void testMaxSizeLimitUnknownContentLength()
-            throws IOException, FileUploadException {
-        final String request =
-            "-----1234\r\n" +
-            "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" +
-            "Content-Type: text/whatever\r\n" +
-            "Content-Length: 10\r\n" +
-            "\r\n" +
-            "This is the content of the file\n" +
-            "\r\n" +
-            "-----1234\r\n" +
-            "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.tab\"\r\n" +
-            "Content-Type: text/whatever\r\n" +
-            "\r\n" +
-            "This is the content of the file\n" +
-            "\r\n" +
-            "-----1234--\r\n";
-
-        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
-        upload.setFileSizeMax(-1);
-        upload.setSizeMax(300);
-
-        // the first item should be within the max size limit
-        // set the read limit to 10 to simulate a "real" stream
-        // otherwise the buffer would be immediately filled
-
-        MockHttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
-        req.setContentLength(-1);
-        req.setReadLimit(10);
-
-        FileItemIterator it = upload.getItemIterator(req);
-        assertTrue(it.hasNext());
-
-        FileItemStream item = it.next();
-        assertFalse(item.isFormField());
-        assertEquals("file1", item.getFieldName());
-        assertEquals("foo1.tab", item.getName());
-
-        {
-            InputStream stream = item.openStream();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            Streams.copy(stream, baos, true);
-        }
-
-        // the second item is over the size max, thus we expect an error
-        try {
-            // the header is still within size max -> this shall still succeed
-            assertTrue(it.hasNext());
-        } catch (SizeException e) {
-            fail();
-        }
-
-        item = it.next();
-
-        try {
-            InputStream stream = item.openStream();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            Streams.copy(stream, baos, true);
-            fail();
-        } catch (FileUploadIOException e) {
-            // expected
-        }
-    }
-
-}
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one or more

+ * contributor license agreements.  See the NOTICE file distributed with

+ * this work for additional information regarding copyright ownership.

+ * The ASF licenses this file to You under the Apache License, Version 2.0

+ * (the "License"); you may not use this file except in compliance with

+ * the License.  You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ */

+package org.apache.commons.fileupload2;

+

+import static org.junit.Assert.assertEquals;

+import static org.junit.Assert.assertFalse;

+import static org.junit.Assert.assertTrue;

+import static org.junit.Assert.fail;

+

+import java.io.ByteArrayOutputStream;

+import java.io.IOException;

+import java.io.InputStream;

+import java.util.Iterator;

+import java.util.List;

+

+import javax.servlet.http.HttpServletRequest;

+

+import org.apache.commons.fileupload2.FileItem;

+import org.apache.commons.fileupload2.FileItemIterator;

+import org.apache.commons.fileupload2.FileItemStream;

+import org.apache.commons.fileupload2.FileUploadException;

+import org.apache.commons.fileupload2.disk.DiskFileItemFactory;

+import org.apache.commons.fileupload2.impl.FileSizeLimitExceededException;

+import org.apache.commons.fileupload2.impl.FileUploadIOException;

+import org.apache.commons.fileupload2.impl.SizeLimitExceededException;

+import org.apache.commons.fileupload2.servlet.ServletFileUpload;

+import org.apache.commons.fileupload2.util.Streams;

+import org.junit.Test;

+

+/**

+ * Unit test for items with varying sizes.

+ */

+public class SizesTest {

+

+    /**

+     * Runs a test with varying file sizes.

+     */

+    @Test

+    public void testFileUpload()

+            throws IOException, FileUploadException {

+        ByteArrayOutputStream baos = new ByteArrayOutputStream();

+        int add = 16;

+        int num = 0;

+        for (int i = 0;  i < 16384;  i += add) {

+            if (++add == 32) {

+                add = 16;

+            }

+            String header = "-----1234\r\n"

+                + "Content-Disposition: form-data; name=\"field" + (num++) + "\"\r\n"

+                + "\r\n";

+            baos.write(header.getBytes("US-ASCII"));

+            for (int j = 0;  j < i;  j++) {

+                baos.write((byte) j);

+            }

+            baos.write("\r\n".getBytes("US-ASCII"));

+        }

+        baos.write("-----1234--\r\n".getBytes("US-ASCII"));

+

+        List<FileItem> fileItems =

+                Util.parseUpload(new ServletFileUpload(new DiskFileItemFactory()), baos.toByteArray());

+        Iterator<FileItem> fileIter = fileItems.iterator();

+        add = 16;

+        num = 0;

+        for (int i = 0;  i < 16384;  i += add) {

+            if (++add == 32) {

+                add = 16;

+            }

+            FileItem item = fileIter.next();

+            assertEquals("field" + (num++), item.getFieldName());

+            byte[] bytes = item.get();

+            assertEquals(i, bytes.length);

+            for (int j = 0;  j < i;  j++) {

+                assertEquals((byte) j, bytes[j]);

+            }

+        }

+        assertTrue(!fileIter.hasNext());

+    }

+

+    /** Checks, whether limiting the file size works.

+     */

+    @Test

+    public void testFileSizeLimit()

+            throws IOException, FileUploadException {

+        final String request =

+            "-----1234\r\n" +

+            "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +

+            "Content-Type: text/whatever\r\n" +

+            "\r\n" +

+            "This is the content of the file\n" +

+            "\r\n" +

+            "-----1234--\r\n";

+

+        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(-1);

+        HttpServletRequest req = new MockHttpServletRequest(

+                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        List<FileItem> fileItems = upload.parseRequest(req);

+        assertEquals(1, fileItems.size());

+        FileItem item = fileItems.get(0);

+        assertEquals("This is the content of the file\n", new String(item.get()));

+

+        upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(40);

+        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        fileItems = upload.parseRequest(req);

+        assertEquals(1, fileItems.size());

+        item = fileItems.get(0);

+        assertEquals("This is the content of the file\n", new String(item.get()));

+

+        upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(30);

+        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        try {

+            upload.parseRequest(req);

+            fail("Expected exception.");

+        } catch (FileSizeLimitExceededException e) {

+            assertEquals(30, e.getPermittedSize());

+        }

+    }

+

+    /** Checks, whether a faked Content-Length header is detected.

+     */

+    @Test

+    public void testFileSizeLimitWithFakedContentLength()

+            throws IOException, FileUploadException {

+        final String request =

+            "-----1234\r\n" +

+            "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" +

+            "Content-Type: text/whatever\r\n" +

+            "Content-Length: 10\r\n" +

+            "\r\n" +

+            "This is the content of the file\n" +

+            "\r\n" +

+            "-----1234--\r\n";

+

+        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(-1);

+        HttpServletRequest req = new MockHttpServletRequest(

+                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        List<FileItem> fileItems = upload.parseRequest(req);

+        assertEquals(1, fileItems.size());

+        FileItem item = fileItems.get(0);

+        assertEquals("This is the content of the file\n", new String(item.get()));

+

+        upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(40);

+        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        fileItems = upload.parseRequest(req);

+        assertEquals(1, fileItems.size());

+        item = fileItems.get(0);

+        assertEquals("This is the content of the file\n", new String(item.get()));

+

+        // provided Content-Length is larger than the FileSizeMax -> handled by ctor

+        upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(5);

+        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        try {

+            upload.parseRequest(req);

+            fail("Expected exception.");

+        } catch (FileSizeLimitExceededException e) {

+            assertEquals(5, e.getPermittedSize());

+        }

+

+        // provided Content-Length is wrong, actual content is larger -> handled by LimitedInputStream

+        upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(15);

+        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        try {

+            upload.parseRequest(req);

+            fail("Expected exception.");

+        } catch (FileSizeLimitExceededException e) {

+            assertEquals(15, e.getPermittedSize());

+        }

+    }

+

+    /** Checks, whether the maxSize works.

+     */

+    @Test

+    public void testMaxSizeLimit()

+            throws IOException, FileUploadException {

+        final String request =

+            "-----1234\r\n" +

+            "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" +

+            "Content-Type: text/whatever\r\n" +

+            "Content-Length: 10\r\n" +

+            "\r\n" +

+            "This is the content of the file\n" +

+            "\r\n" +

+            "-----1234\r\n" +

+            "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.tab\"\r\n" +

+            "Content-Type: text/whatever\r\n" +

+            "\r\n" +

+            "This is the content of the file\n" +

+            "\r\n" +

+            "-----1234--\r\n";

+

+        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(-1);

+        upload.setSizeMax(200);

+

+        MockHttpServletRequest req = new MockHttpServletRequest(

+                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        try {

+            upload.parseRequest(req);

+            fail("Expected exception.");

+        } catch (SizeLimitExceededException e) {

+            assertEquals(200, e.getPermittedSize());

+        }

+    }

+

+    @Test

+    public void testMaxSizeLimitUnknownContentLength()

+            throws IOException, FileUploadException {

+        final String request =

+            "-----1234\r\n" +

+            "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" +

+            "Content-Type: text/whatever\r\n" +

+            "Content-Length: 10\r\n" +

+            "\r\n" +

+            "This is the content of the file\n" +

+            "\r\n" +

+            "-----1234\r\n" +

+            "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.tab\"\r\n" +

+            "Content-Type: text/whatever\r\n" +

+            "\r\n" +

+            "This is the content of the file\n" +

+            "\r\n" +

+            "-----1234--\r\n";

+

+        ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());

+        upload.setFileSizeMax(-1);

+        upload.setSizeMax(300);

+

+        // the first item should be within the max size limit

+        // set the read limit to 10 to simulate a "real" stream

+        // otherwise the buffer would be immediately filled

+

+        MockHttpServletRequest req = new MockHttpServletRequest(

+                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);

+        req.setContentLength(-1);

+        req.setReadLimit(10);

+

+        FileItemIterator it = upload.getItemIterator(req);

+        assertTrue(it.hasNext());

+

+        FileItemStream item = it.next();

+        assertFalse(item.isFormField());

+        assertEquals("file1", item.getFieldName());

+        assertEquals("foo1.tab", item.getName());

+

+        {

+            InputStream stream = item.openStream();

+            ByteArrayOutputStream baos = new ByteArrayOutputStream();

+            Streams.copy(stream, baos, true);

+        }

+

+        // the second item is over the size max, thus we expect an error

+        try {

+            // the header is still within size max -> this shall still succeed

+            assertTrue(it.hasNext());

+        } catch (SizeLimitExceededException e) {

+            fail();

+        }

+

+        item = it.next();

+

+        try {

+            InputStream stream = item.openStream();

+            ByteArrayOutputStream baos = new ByteArrayOutputStream();

+            Streams.copy(stream, baos, true);

+            fail();

+        } catch (FileUploadIOException e) {

+            // expected

+        }

+    }

+

+}

diff --git a/src/test/java/org/apache/commons/fileupload2/StreamingTest.java b/src/test/java/org/apache/commons/fileupload2/StreamingTest.java
index b80bee0..d173bdf 100644
--- a/src/test/java/org/apache/commons/fileupload2/StreamingTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/StreamingTest.java
@@ -33,8 +33,8 @@
 import org.apache.commons.fileupload2.FileUploadException;
 import org.apache.commons.fileupload2.InvalidFileNameException;
 import org.apache.commons.fileupload2.MultipartStream;
-import org.apache.commons.fileupload2.FileUploadBase.IOFileUploadException;
 import org.apache.commons.fileupload2.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload2.impl.IOFileUploadException;
 import org.apache.commons.fileupload2.servlet.ServletFileUpload;
 import org.apache.commons.fileupload2.servlet.ServletRequestContext;