// The line below throws a SizeLimitExceededException (wrapped by a
// FileUploadIOException) if the request is longer than the max size
// allowed by fileupload requests (FileUpload.getSizeMax)
// But note that if the request does not send proper headers this check
// just will not do anything and we still have to check it again.
FileItemIterator iter = fileUpload
.getItemIterator(new ServletRequestContext(request));
FileItemFactory fac = fileUpload.getFileItemFactory();
if (fac == null)
{
throw new NullPointerException(
"No FileItemFactory has been set.");
}
long maxFileSize = this.getFileSizeMax();
long maxSize = this.getSizeMax();
boolean checkMaxSize = false;
if (maxFileSize == -1L)
{
//The max allowed file size should be approximate to the maxSize
maxFileSize = maxSize;
}
if (maxSize != -1L)
{
checkMaxSize = true;
}
while (iter.hasNext())
{
final FileItemStream item = iter.next();
FileItem fileItem = fac.createItem(item.getFieldName(), item
.getContentType(), item.isFormField(), item.getName());
long allowedLimit = 0L;
try