You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2010/06/06 23:19:57 UTC
svn commit: r951978 [2/5] - in /commons/sandbox/commons-fileupload2: ./
.settings/ src/ src/changes/ src/checkstyle/ src/conf/ src/java/
src/java/org/ src/java/org/apache/ src/java/org/apache/commons/
src/java/org/apache/commons/fileupload2/ src/java/o...
Added: commons/sandbox/commons-fileupload2/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/changes/changes.xml?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/changes/changes.xml (added)
+++ commons/sandbox/commons-fileupload2/src/changes/changes.xml Sun Jun 6 21:19:54 2010
@@ -0,0 +1,460 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!--
+This file is used by the maven-changes-plugin to generate the release notes.
+Useful ways of finding items to add to this file are:
+
+1. Add items when you fix a bug or add a feature (this makes the
+release process easy :-).
+
+2. Do a bugzilla search for tickets closed since the previous release.
+
+3. Use the report generated by the maven-changelog-plugin to see all
+CVS commits. Set the project.properties' maven.changelog.range
+property to the number of days since the last release.
+
+
+The <action> type attribute can be add,update,fix,remove.
+-->
+
+<document>
+
+ <properties>
+ <title>Release Notes</title>
+ <author email="martinc@apache.org">Martin Cooper</author>
+ </properties>
+
+ <body>
+ <release version="1.3-SNAPSHOT" date="Not yet released">
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-160"
+ due-to="Stepan Koltsov" due-to-email="yozh@mx1.ru">
+ Temporary files have not been deleted, if an error
+ occurred in FileUploadBase.parseRequest();
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-158"
+ due-to="Stepan Koltsov" due-to-email="yozh@mx1.ru">
+ Fixed example in MultipartStream Javadocs.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-157"
+ due-to="Paul Spurr" due-to-email="pspurr@gmail.com">
+ Ensured, that the ProgressListener is called for all
+ items.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-156">
+ Made the ProgressNotifier public.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-155"
+ due-to="Jörg Heinicke" due-to-email="joerg.heinicke@gmx.de">
+ Multiple documentation fixes.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-152"
+ due-to="Duzakropka" due-to-email="duzakropka.@gmail.com">
+ Fixed the error message for FileSizeLimitExceededException
+ from "too many characters" to "too many bytes".
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-154">
+ A FileSizeLimitExceededException does now contain the
+ file and field name of the item, which caused the problem.
+ </action>
+ </release>
+
+ <release version="1.2.1" date="2008-01-18">
+ <action dev="jochen" type="fix">
+ Upgrade to commons-io-1.4-SNAPSHOT, in order to use the new
+ FileCleaningTracker and fix issues with FileCleaner.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-129">
+ Made the MockHttpServletRequest comply to the servlet 2.4 specification
+ by applying
+ http://www.sourcelabs.com/dashboards/sash-1.2/patches/commons-fileupload-1.1-1/SUP-520.diff
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-130"
+ due-to="Michael Macaluso" due-to-email="michael.public@wavecorp.com">
+ Added support for accessing the file item headers.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-116"
+ due-to="Amichai Rothman" due-to-email="amichai2@amichais.net">
+ A MalformedStreamException is now thrown, if the size of an items
+ headers exceeds HEADER_PART_SIZE_MAX;
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-134"
+ due-to="Thomas Vandahl" due-to-email="tv@apache.org">
+ DiskFileItem.toString() could throw an NPE.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-135"
+ 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. Additionally, the FileSizeLimitException
+ is now thrown immediately, if the attachments headers contain
+ a content-length value, which exceeds the configured limit.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-153"
+ due-to="Gary Gregory" due-to-email="ggregory@seagullsw.com">
+ Fixed a classpath problem when building with Sun JDK 1.3.1
+ and Ant.
+ </action>
+ </release>
+
+ <release version="1.2" date="2007-02-13">
+ <action dev="jochen" type="fix" due-to="Aaron Freeman"
+ due-to-email="aaron@sendthisfile.com">
+ Made Streams.asString static.
+ </action>
+ <action dev="jochen" type="update" issue="FILEUPLOAD-109">
+ Eliminated duplicate code.
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-112">
+ Added a streaming API.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-93">
+ Eliminated the necessity of a content-length header.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-108"
+ due-to="Amichai Rothman" due-to-email="amichai2@amichais.net">
+ Eliminated the limitation of a maximum size for a single
+ header line. (The total size of all headers is already
+ limited, so there's no need for another limit.)
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-87">
+ Added the ProgressListener, which allows to implement a
+ progress bar.
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-111"
+ due-to="Amichai Rothman" due-to-email="amichai2@amichais.net">
+ Added support for header continuation lines.
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-88"
+ due-to="Andrey Aristarkhov" due-to-email="aristarkhov@bitechnology.ru">
+ It is now possible to limit the actual file size and not
+ the request size.
+ </action>
+ <action dev="jochen" type="add" issue="FILEUPLOAD-120"
+ due-to="Henry Yandell" due-to-email="bayard@apache.org">
+ Added the FileCleanerCleanup as an example for how to close
+ down the FileCleaner's reaper thread nicely.
+ </action>
+ <action dev="jochen" type="fix" issue="FILEUPLOAD-123">
+ A descriptive NPE is now thrown, if the FileItemFactory
+ has not been set.
+ </action>
+ </release>
+
+ <release version="1.1.1" date="2006-06-08" description="Bugfix release">
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-20">
+ Cache disk file item size when it is moved to a new location.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-30">
+ File names were being inadvertently converted to lower case.
+ </action>
+
+ </release>
+
+ <release version="1.1" date="2005-12-24" description="Portlet support, substantial refactoring and numerous bug fixes">
+
+ <action dev="martinc" type="update">
+ Updates for FileUpload 1.1-RC1.
+ </action>
+
+ <action dev="martinc" type="add">
+ Added release notes for FileUpload 1.1.
+ </action>
+
+ <action dev="martinc" type="update">
+ Update the User Guide to document the "right" way of using FileUpload
+ 1.1, rather than the older, and thus deprecated, ways that are
+ compatible with FileUpload 1.0.
+ </action>
+
+ <action dev="martinc" type="add">
+ Add this change log, including all changes since the Commons FileUpload
+ 1.0 release.
+ </action>
+
+ <action dev="martinc" type="update">
+ Update Commons IO dependency to version 1.1.
+ </action>
+
+ <action dev="martinc" type="add">
+ Add custom PMD configuration.
+ </action>
+
+ <action dev="martinc" type="update">
+ Make inner exception classes static, which they should have been all
+ along.
+ </action>
+
+ <action dev="martinc" type="fix">
+ Fix Checkstyle warnings.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-29" due-to="Rahul Akolkar">
+ Remove Javadoc warnings.
+ </action>
+
+ <action dev="martinc" type="update">
+ Build updates:
+ <ul>
+ <li>
+ Include NOTICE.txt in the jar file and distributions.
+ </li>
+ <li>
+ Include xdocs in source distribution.
+ </li>
+ <li>
+ Create MD5 checksums for distributions.
+ </li>
+ </ul>
+ </action>
+
+ <action dev="martinc" type="add">
+ Add custom Checkstyle configuration.
+ </action>
+
+ <action dev="martinc" type="update">
+ Update dependencies in POM, and add comments and scope.
+ </action>
+
+ <action dev="martinc" type="update">
+ Standardise on @throws instead of having a mixture of that and
+ @exception.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-50" due-to="Niall Pemberton">
+ Make DiskFileItem serializable. Thanks to Niall Pemberton for the
+ suggestion and patch.
+ </action>
+
+ <action dev="martinc" type="update">
+ Make the temporary file names unique across class loaders, not just
+ within them, by including a UID in the file name.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-77">
+ Include the actual and permitted sizes in both the exception message
+ and the exception itself.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-13">
+ If an explicit header encoding is not specified, use the one from the
+ appropriate context (i.e. ServletRequest or ActionRequest).
+ </action>
+
+ <action dev="martinc" type="add">
+ Add getCharacterEncoding to the request context.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-83">
+ Null check and case insensitivity fixes.
+ </action>
+
+ <action dev="martinc" type="update">
+ Web site updates:
+ <ul>
+ <li>
+ Add detail pages for Source Repository and Issue Tracking, based on
+ those for IO and Validator.
+ </li>
+ <li>
+ Improvements to FileUpload home page, based on similar recent
+ changes to IO and Validator home pages.
+ </li>
+ <li>
+ The Bugzilla component name has a space in it. Fix the URLs.
+ </li>
+ <li>
+ Add an FAQ page, using the Maven plugin to generate it.
+ </li>
+ </ul>
+ </action>
+
+ <action dev="dion" type="fix" issue="COMMONSSITE-2">
+ Fixes to POMs
+ </action>
+
+ <action dev="mrdon" type="update">
+ Setting source and target for Java 1.3
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-37">
+ Fix typos in Javadoc code examples.
+ </action>
+
+ <action dev="martinc" type="fix">
+ Fix typos in exception messages.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-5">
+ Obtain request content type from container instead of headers.
+ </action>
+
+ <action dev="sullis" type="update">
+ New mock objects from Jetspeed-2, and new FileUpload test cases.
+ </action>
+
+ <action dev="sullis" type="add">
+ added toString() methods
+ </action>
+
+ <action dev="martinc" type="add">
+ Fix up the existing package.html file and add new ones for the newly
+ introduced packages. Fairly minimal, but with a link to the user guide.
+ </action>
+
+ <action dev="martinc" type="update">
+ Substantial refactoring and additions:
+ <ul>
+ <li>
+ The core package is now independent of servlet / portlet / other
+ distinctions, as well as persistence schemes, other than deprecated
+ classes and methods retained for backwards compatibility.
+ </li>
+ <li>
+ Servlet specific functionality has been moved to a new 'servlet'
+ package. Existing users should migrate to this as soon as possible,
+ since the servlet specific functionality in the generic package
+ will be removed in the release after FileUpload 1.1.
+ </li>
+ <li>
+ Support for portlets (JSR 168) has been added, in a new 'portlet'
+ package. This is not well tested at this point, and feedback would
+ be very much appreciated. (This also resolves bug #23620.)
+ </li>
+ <li>
+ The disk-based file item implementation has been moved into a 'disk'
+ package, and renamed from Default* to Disk* to reflect what it
+ really is. The Default* classes have been retained in the top level
+ package for backwards compatibility, but are now deprecated, and
+ will be removed in the release after FileUpload 1.1.
+ </li>
+ <li>
+ The isMultipartRequest method is an unfortunate casualty of this
+ refactoring. That method should really be moved to ServletFileUpload,
+ but since the method is static, it can only exist in either
+ FileUploadBase or ServletFileUpload. Backwards compatibility dictates
+ the former for now, but the latter is the desired state, which
+ implies some future breakage. Fair warning...
+ </li>
+ </ul>
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-4">
+ Specify the encoding (ISO-8859-1) when converting the boundary to a
+ byte array.
+ </action>
+
+ <action dev="martinc" type="update">
+ Convert to Sun coding guidelines.
+ </action>
+
+ <action dev="martinc" type="update">
+ DeferredFileOutputStream moved to Commons IO.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-16" due-to="Justin Sampson">
+ Workaround for Mac IE5 bug. Thanks to Justin Sampson for the patch and
+ tests for this vexing issue.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-104">
+ Handle unquoted header parameters.
+ </action>
+
+ <action dev="martinc" type="add" issue="FILEUPLOAD-78">
+ Some documentation on interaction with virus scanners.
+ </action>
+
+ <action dev="martinc" type="add" issue="FILEUPLOAD-31" due-to="Justin Sampson">
+ More unit tests from Justin Sampson.
+ </action>
+
+ <action dev="martinc" type="update" issue="FILEUPLOAD-95">
+ Use FileCleaner from Commons IO to clean up temp files, rather than
+ File.deleteOnExit(), which can cause serious problems in long-running
+ processes.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-53">
+ Check that HTTP method is POST as part of multipart check.
+ </action>
+
+ <action dev="martinc" type="add">
+ Switch to Commons IO version of DeferredFileOutputStream. Adding IO as
+ a dependency will allow us to take advantage of other classes in that
+ component to fix additional FileUpload bugs.
+ </action>
+
+ <action dev="martinc" type="add" issue="FILEUPLOAD-40">
+ handle quoted boundary specification.
+ </action>
+
+ <action dev="martinc" type="add" issue="FILEUPLOAD-18">
+ use case-independent comparisons for encoding types.
+ </action>
+
+ <action dev="martinc" type="fix">
+ Fix comments to avoid break iterator complaints.
+ </action>
+
+ <action dev="martinc" type="fix" due-to="Yuji Yamano">
+ Fix typos in comments.
+ </action>
+
+ <action dev="martinc" type="add" issue="FILEUPLOAD-101" due-to="Oleg Kalnichevski">
+ Add support for character sets specified for individual parts.
+ </action>
+
+ <action dev="scolebourne" type="update">
+ Change to Apache License 2.0
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-22">
+ Correct the comment for the no-args constructor to reflect the fact
+ that a factory needs to be set before parsing uploads.
+ </action>
+
+ <action dev="martinc" type="update">
+ Collapse some all but duplicated code.
+ </action>
+
+ <action dev="jmcnally" type="fix" issue="FILEUPLOAD-72">
+ Fix example showing FileItem.write to use a File object.
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-21" due-to="Peter Chase">
+ Check for null before attempting to close streams in write().
+ </action>
+
+ <action dev="martinc" type="fix" issue="FILEUPLOAD-67" due-to="Paul Dalton">
+ Correction to sample code in the docs.
+ </action>
+
+ </release>
+
+ <release version="1.0" date="2003-06-26" description="Initial release">
+ </release>
+
+
+ </body>
+
+</document>
Propchange: commons/sandbox/commons-fileupload2/src/changes/changes.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_basic.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_basic.xml?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_basic.xml (added)
+++ commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_basic.xml Sun Jun 6 21:19:54 2010
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<ruleset name="FileUpload Basic Rules">
+ <description>PMD Basic Ruleset minus the EmptyCatchBlock rule.</description>
+
+ <rule ref="rulesets/basic.xml">
+ <exclude name="EmptyCatchBlock"/>
+ </rule>
+</ruleset>
Propchange: commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_basic.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_checks.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_checks.xml?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_checks.xml (added)
+++ commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_checks.xml Sun Jun 6 21:19:54 2010
@@ -0,0 +1,224 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.1//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_1.dtd">
+
+<!--
+ Checkstyle configuration for Commons FileUpload. FileUpload uses the Sun
+ coding guidelines, so this file is almost the same as Maven's sun_checks.xml
+ file. The only changes from that file are:
+
+ - Use a RegexpHeader check instead of a regular Header check, since the
+ copyright years can vary per source file.
+
+ - Disable the HiddenField module, since FileUpload has always used the
+ "this.foo = foo" pattern, which is not recognised by this module.
+
+ - Disable the DesignForExtension module, since fixing those complaints
+ would result in backwards incompatible API changes.
+
+ - Disable the FinalParameters module, since fixing those complaints
+ would result in backwards incompatible API changes.
+-->
+<!--
+
+ Checkstyle configuration that checks the sun coding conventions from:
+
+ - the Java Language Specification at
+ http://java.sun.com/docs/books/jls/second_edition/html/index.html
+
+ - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
+
+ - the Javadoc guidelines at
+ http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
+
+ - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
+
+ - some best practices
+
+ Checkstyle is very configurable. Be sure to read the documentation at
+ http://checkstyle.sf.net (or in your downloaded distribution).
+
+ Most Checks are configurable, be sure to consult the documentation.
+
+ To completely disable a check, just comment it out or delete it from the file.
+
+ Finally, it is worth reading the documentation.
+
+-->
+
+<module name="Checker">
+
+ <!-- Checks that a package.html file exists for each package. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html#PackageHtml -->
+ <module name="PackageHtml"/>
+
+ <!-- Checks whether files end with a new line. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
+ <module name="NewlineAtEndOfFile"/>
+
+ <!-- Checks that property files contain the same keys. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
+ <module name="Translation"/>
+
+
+ <module name="TreeWalker">
+
+ <property name="cacheFile" value="${checkstyle.cache.file}"/>
+
+ <!-- Checks for Javadoc comments. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
+ <module name="JavadocMethod">
+ <property name="scope" value="protected"/>
+ <property name="allowUndeclaredRTE" value="true"/>
+ <property name="allowThrowsTagsForSubclasses" value="true"/>
+ </module>
+ <module name="JavadocType"/>
+ <module name="JavadocVariable"/>
+ <module name="JavadocStyle"/>
+
+
+ <!-- Checks for Naming Conventions. -->
+ <!-- See http://checkstyle.sf.net/config_naming.html -->
+ <module name="ConstantName"/>
+ <module name="LocalFinalVariableName"/>
+ <module name="LocalVariableName"/>
+ <module name="MemberName"/>
+ <module name="MethodName"/>
+ <module name="PackageName"/>
+ <module name="ParameterName"/>
+ <module name="StaticVariableName"/>
+ <module name="TypeName"/>
+
+
+ <!-- Checks for Headers -->
+ <!-- See http://checkstyle.sf.net/config_header.html -->
+ <!-- <module name="Header"> -->
+ <!-- The follow property value demonstrates the ability -->
+ <!-- to have access to ANT properties. In this case it uses -->
+ <!-- the ${basedir} property to allow Checkstyle to be run -->
+ <!-- from any directory within a project. See property -->
+ <!-- expansion, -->
+ <!-- http://checkstyle.sf.net/config.html#properties -->
+ <!-- <property -->
+ <!-- name="headerFile" -->
+ <!-- value="${basedir}/java.header"/> -->
+ <!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
+ <!-- </module> -->
+
+ <!-- Following interprets the header file as regular expressions. -->
+ <!-- <module name="RegexpHeader"/> -->
+ <module name="RegexpHeader">
+ <property name="headerFile" value="${checkstyle.header.file}"/>
+ </module>
+
+
+ <!-- Checks for imports -->
+ <!-- See http://checkstyle.sf.net/config_import.html -->
+ <module name="AvoidStarImport"/>
+ <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
+ <module name="RedundantImport"/>
+ <module name="UnusedImports"/>
+
+
+ <!-- Checks for Size Violations. -->
+ <!-- See http://checkstyle.sf.net/config_sizes.html -->
+ <module name="FileLength"/>
+ <!-- Begin Custom for FileUpload -->
+ <module name="LineLength">
+ <property name="ignorePattern" value="^ \* @version .*$"/>
+ </module>
+ <!-- End Custom for FileUpload -->
+ <module name="MethodLength"/>
+ <module name="ParameterNumber"/>
+
+
+ <!-- Checks for whitespace -->
+ <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+ <module name="EmptyForIteratorPad"/>
+ <module name="NoWhitespaceAfter"/>
+ <module name="NoWhitespaceBefore"/>
+ <module name="OperatorWrap"/>
+ <module name="ParenPad"/>
+ <module name="TypecastParenPad"/>
+ <module name="TabCharacter"/>
+ <module name="WhitespaceAfter"/>
+ <module name="WhitespaceAround"/>
+
+
+ <!-- Modifier Checks -->
+ <!-- See http://checkstyle.sf.net/config_modifiers.html -->
+ <module name="ModifierOrder"/>
+ <module name="RedundantModifier"/>
+
+
+ <!-- Checks for blocks. You know, those {}'s -->
+ <!-- See http://checkstyle.sf.net/config_blocks.html -->
+ <module name="AvoidNestedBlocks"/>
+ <!-- Begin Custom for FileUpload -->
+ <module name="EmptyBlock">
+ <property name="option" value="text"/>
+ </module>
+ <!-- End Custom for FileUpload -->
+ <module name="LeftCurly"/>
+ <module name="NeedBraces"/>
+ <module name="RightCurly"/>
+
+
+ <!-- Checks for common coding problems -->
+ <!-- See http://checkstyle.sf.net/config_coding.html -->
+ <module name="AvoidInlineConditionals"/>
+ <module name="DoubleCheckedLocking"/> <!-- MY FAVOURITE -->
+ <module name="EmptyStatement"/>
+ <module name="EqualsHashCode"/>
+ <!-- Disabled for FileUpload: module name="HiddenField"/ -->
+ <module name="IllegalInstantiation"/>
+ <module name="InnerAssignment"/>
+ <module name="MagicNumber"/>
+ <module name="MissingSwitchDefault"/>
+ <module name="RedundantThrows">
+ <property name="allowSubclasses" value="true"/>
+ </module>
+ <module name="SimplifyBooleanExpression"/>
+ <module name="SimplifyBooleanReturn"/>
+
+ <!-- Checks for class design -->
+ <!-- See http://checkstyle.sf.net/config_design.html -->
+ <!-- Disabled for FileUpload: module name="DesignForExtension"/ -->
+ <module name="FinalClass"/>
+ <module name="HideUtilityClassConstructor"/>
+ <module name="InterfaceIsType"/>
+ <module name="VisibilityModifier"/>
+
+
+ <!-- Miscellaneous other checks. -->
+ <!-- See http://checkstyle.sf.net/config_misc.html -->
+ <module name="ArrayTypeStyle"/>
+ <!-- Disabled for FileUpload: module name="FinalParameters"/ -->
+ <module name="GenericIllegalRegexp">
+ <property name="format" value="\s+$"/>
+ <property name="message" value="Line has trailing spaces."/>
+ </module>
+ <module name="TodoComment"/>
+ <module name="UpperEll"/>
+
+ </module>
+
+</module>
Propchange: commons/sandbox/commons-fileupload2/src/checkstyle/fileupload_checks.xml
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/checkstyle/license-header.txt
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/checkstyle/license-header.txt?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/checkstyle/license-header.txt (added)
+++ commons/sandbox/commons-fileupload2/src/checkstyle/license-header.txt Sun Jun 6 21:19:54 2010
@@ -0,0 +1,16 @@
+/\*\s*
+ \*\s*Licensed to the Apache Software Foundation \(ASF\) under one or more
+ \*\s*contributor license agreements. See the NOTICE file distributed with
+ \*\s*this work for additional information regarding copyright ownership\.
+ \*\s*The ASF licenses this file to You under the Apache License, Version 2\.0
+ \*\s*\(the "License"\); you may not use this file except in compliance with
+ \*\s*the License\. You may obtain a copy of the License at
+ \*\s*
+ \*\s*http://www\.apache\.org/licenses/LICENSE\-2\.0
+ \*\s*
+ \*\s*Unless required by applicable law or agreed to in writing, software
+ \*\s*distributed under the License is distributed on an "AS IS" BASIS,
+ \*\s*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.
+ \*\s*See the License for the specific language governing permissions and
+ \*\s*limitations under the License\.
+ \*/\s*
Propchange: commons/sandbox/commons-fileupload2/src/checkstyle/license-header.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/conf/MANIFEST.MF
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/conf/MANIFEST.MF?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/conf/MANIFEST.MF (added)
+++ commons/sandbox/commons-fileupload2/src/conf/MANIFEST.MF Sun Jun 6 21:19:54 2010
@@ -0,0 +1,5 @@
+Specification-Vendor: Apache Software Foundation
+Specification-Title: Commons FileUpload
+Implementation-Vendor: Apache Software Foundation
+Implementation-Vendor-Id: org.apache
+Implementation-Title: Commons FileUpload
Propchange: commons/sandbox/commons-fileupload2/src/conf/MANIFEST.MF
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/EventListener.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/EventListener.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/EventListener.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/EventListener.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,156 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.commons.fileupload2.impl.DefaultEventListener;
+
+
+/**
+ * <p>The {@link EventListener} may be used to display a progress bar
+ * or do stuff like that. A typical sequence of events would look like
+ * this:
+ * <pre>
+ * startRequest(FileUpload,Request)
+ * startItem(FileUpload,Request,FileItem)
+ * parsingItem(FileUpload,Request,FileItem,long)
+ * ...
+ * parsingItem(FileUpload,Request,FileItem,long)
+ * endItem(FileUpload,Request,FileItem,long)
+ * startItem(FileUpload,Request,FileItem)
+ * parsingItem(FileUpload,Request,FileItem,long)
+ * endItem(FileUpload,Request,FileItem,long)
+ * ...
+ * endRequest(FileUpload,Request)
+ * </pre>
+ * The example shows processing of a request, which contains at two or
+ * more {@link FileItem file items}.</p>
+ * <p>While parsing a file item, the event listener will call the
+ * method {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)} from time
+ * to time. Whether and when this happens for the first time, is
+ * decided by the value returned by the method {@link #startItem(FileUpload, UploadRequest, FileItem)}:
+ * If this method returns the value {@link #NO_PARSING_ITEM_CALLS}, then
+ * a call to {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)} will
+ * never occur. However, if the value returned by
+ * {@link #startItem(FileUpload, UploadRequest, FileItem)} is non-negative, then the
+ * {@link FileUpload} object will attempt to call
+ * {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)} as soon as it detects,
+ * that at least the given number of bytes have been parsed from the
+ * item. However, due to buffer size and other environmental influences,
+ * such calls aren't guaranteed.</p>
+ * <p><em>Thread safety</em>: The event listeners interface is designed
+ * in a manner, which allows to handle concurrent requests with a single
+ * event listener instance. However, in that case the implementor is
+ * responsible for creating a thread safe event listener. The recommended
+ * approach is to create a new event listener per request.</p>
+ * <p><em>Implementation note</em>: Implementors are strongly encouraged
+ * to derive from {@link DefaultEventListener}, because this will ensure
+ * upwards compatibility in the case of new events, which might be added
+ * later on.</p>
+ */
+public interface EventListener {
+ /**
+ * Constant to return by {@link #startItem(FileUpload, UploadRequest, FileItem)},
+ * or {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)}, if the
+ * event listener wishes to prevent calls to
+ * {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)}.
+ * @see #startItem(FileUpload, UploadRequest, FileItem)
+ * @see #parsingItem(FileUpload, UploadRequest, FileItem, long)
+ */
+ public static final long NO_PARSING_ITEM_CALLS = -1;
+
+ /**
+ * Called to indicate that the request processing begins.
+ */
+ public void startRequest(FileUpload pFileUpload, UploadRequest pRequest) throws IOException;
+
+ /**
+ * Called to indicate that the request processing was successful.
+ */
+ public void endRequest(FileUpload pFileUpload, UploadRequest pRequest) throws IOException;
+
+ /**
+ * Called to indicate that the requests maximum size was exceeded.
+ */
+ public void requestSizeMaxExceeded(FileUpload pFileUpload, UploadRequest pRequest, long pRequestSize) throws IOException;
+
+ /**
+ * Called to indicate that an error occurred while processing
+ * the request. Note, that {@link #endRequest(FileUpload, UploadRequest)} won't
+ * be called.
+ */
+ public void error(FileUpload pFileUpload, UploadRequest pRequest, Throwable pError) throws IOException;
+
+ /**
+ * Called to indicate that a new {@link FileItem} was found
+ * and is being parsed.
+ * @return The number of bytes, after which {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)}
+ * should be called. May be {@link #NO_PARSING_ITEM_CALLS}, in
+ * which case the method won't be invoked at all.
+ * @see #parsingItem(FileUpload, UploadRequest, FileItem, long)
+ * @see #endItem(FileUpload, UploadRequest, FileItem, long)
+ * @see #NO_PARSING_ITEM_CALLS
+ */
+ public long startItem(FileUpload pFileUpload, UploadRequest pRequest, FileItem pItem) throws IOException;
+
+ /**
+ * Called to indicate that a {@link FileItem file item's} size
+ * exceeds the limit, which is configured by {@link FileUpload#getFileSizeMax()}.
+ */
+ public void fileSizeMaxExceeded(FileUpload pFileUpload, UploadRequest pRequest, FileItem pItem, long pFileSize) throws IOException;
+
+ /**
+ * Called to indicate that a {@link FileItem} was successfully
+ * parsed.
+ * @param pFileUpload The file upload object, which calls the event listener.
+ * @param pItem The file item, which has just been parsed.
+ * @param pContentLength The file items actually known content length.
+ * Unlike the value returned by {@link FileItem#getContentLength()},
+ * this will never be -1. However, the known content length may be
+ * lower than the actual content length, if the file item stream
+ * was closed before it indicated the end of the stream.
+ * @see #startItem(FileUpload, UploadRequest, FileItem)
+ * @see #parsingItem(FileUpload, UploadRequest, FileItem, long)
+ */
+ public void endItem(FileUpload pFileUpload, UploadRequest pRequest, FileItem pItem, long pContentLength) throws IOException;
+
+ /**
+ * Called to indicate that a {@link FileItem} is currently
+ * being parsed. Whether this method is invoked, and when, depends on
+ * the value returned by {@link #startItem(FileUpload, UploadRequest, FileItem)}, and
+ * {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)}. For example,
+ * if both methods return 100 and the file items length is 236, then
+ * the method would be called roughly 2 times (after the first and the
+ * second 100 bytes). Note, that the interval isn't exact and depends
+ * on buffer size and similar circumstances. The contract of the
+ * {@link EventListener} guarantees only a maximum number of
+ * invocations. For example, if the buffer size is 8192 bytes, which
+ * are processed by a single parser invocation, then the method
+ * {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)} won't be invoked
+ * at all, because {@link #endItem(FileUpload, UploadRequest, FileItem, long)} will
+ * be invoked immediately. However, you can rely on the fact that the
+ * method won't be invoked more than 2 times.
+ * @return The number of bytes, after which {@link #parsingItem(FileUpload, UploadRequest, FileItem, long)}
+ * should be called again. May be {@link #NO_PARSING_ITEM_CALLS}, in
+ * which case no more invocations will happen for this file item.
+ * @see #startItem(FileUpload, UploadRequest, FileItem)
+ * @see #endItem(FileUpload, UploadRequest, FileItem, long)
+ * @see #NO_PARSING_ITEM_CALLS
+ */
+ public long parsingItem(FileUpload pFileUpload, UploadRequest pRequest, FileItem pItem, long pCurrentLength) throws IOException;
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/EventListener.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItem.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItem.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItem.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItem.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,127 @@
+/*
+ * 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+/**
+ * <p>This class represents a file or form item that was received within a
+ * <code>multipart/form-data</code> POST request.</p>
+ * <p>The file or form items contents are available by invoking
+ * either of the methods {@link #getInputStream()},
+ * or {@link #getReader(String)}. Note,
+ * that these methods are mutually exclusive and may be invoked
+ * only once.</p>
+ */
+public interface FileItem {
+ /**
+ * Returns the content type passed by the browser or <code>null</code> if
+ * not defined.
+ *
+ * @return The content type passed by the browser or <code>null</code> if
+ * not defined.
+ */
+ String getContentType();
+
+ /**
+ * Returns the original filename in the client's filesystem, as provided by
+ * the browser (or other client software). In most cases, this will be the
+ * base file name, without path information. However, some clients, such as
+ * the Opera browser, do include path information.
+ *
+ * @return The original filename in the client's filesystem.
+ */
+ String getFileName();
+
+ /**
+ * Returns the size of the file item, if known.
+ *
+ * @return The size of the file item, in bytes, if known, or
+ * {@link UploadRequest#UNKNOWN_CONTENT_LENGTH}.
+ */
+ long getContentLength();
+
+ /**
+ * Returns the name of the field in the multipart form corresponding to
+ * this file item.
+ *
+ * @return The name of the form field.
+ */
+ String getFieldName();
+
+ /**
+ * Returns, whether the file item is in fact a simple form field.
+ * If the file item is not a simple form field, then the value
+ * returned by {@link #getFileName()} is valid. Otherwise, the value
+ * returned by {@link #getFileName()} will most likely be
+ * null, and should be ignored.
+ * @return True, if the file item is a simple form field; false,
+ * if the file item is an uploaded file.
+ */
+ boolean isFormField();
+
+ /**
+ * Returns the items encoding.
+ * @return The items encoding, if specified, or null.
+ */
+ String getEncoding();
+
+ /**
+ * <p>Returns an {@link java.io.InputStream InputStream} that can be
+ * used to retrieve the contents of the file item.</p>
+ * <p><em>Note</em>: The methods {@link #getInputStream()}, and
+ * {@link #getReader(String)} are mutually exclusive. You may invoke
+ * only one of them, and invoke it only once.</p>
+ *
+ * @return An {@link java.io.InputStream InputStream} that can be
+ * used to retrieve the contents of the file item.
+ *
+ * @throws FileUploadException The file item stream could not be parsed,
+ * or was otherwise invalid.
+ * @throws IOException An I/O error occurred while reading the underlying
+ * data stream.
+ * @see #getReader(String)
+ */
+ InputStream getInputStream() throws FileUploadException, IOException;
+
+ /**
+ * <p>Returns the contents of the file item as a reader, using the
+ * specified encoding.</p>
+ * <p><em>Note</em>: The methods {@link #getInputStream()}, and
+ * {@link #getReader(String)} are mutually exclusive. You may invoke
+ * only one of them, and invoke it only once.</p>
+ *
+ * @param pEncoding The character encoding to use for conversion of
+ * bytes into characters.
+ * @return An {@link java.io.Reader Reader} that can be
+ * used to retrieve the contents of the file item.
+ *
+ * @throws FileUploadException The file item stream could not be parsed,
+ * or was otherwise invalid.
+ * @throws UnsupportedEncodingException The given encoding is not supported.
+ * @throws IOException An I/O error occurred while reading the underlying
+ * data stream.
+ *
+ * @see #getReader(String)
+ * @see #getEncoding()
+ */
+ Reader getReader(String pEncoding)
+ throws FileUploadException, UnsupportedEncodingException, IOException;
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemIterator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemIterator.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemIterator.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemIterator.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,32 @@
+package org.apache.commons.fileupload2;
+
+import java.io.IOException;
+import java.util.NoSuchElementException;
+
+
+/**
+ * A {@link FileItemIterator file item iterator} is
+ * returned by {@link FileUpload#parse(UploadRequest)}. It allows
+ * to traverse over the file items, which have been sent by
+ * the client.
+ */
+public interface FileItemIterator<FI extends FileItem> {
+ /**
+ * @throws FileUploadException The request could not be parsed or
+ * was otherwise invalid.
+ * @throws IOException An error occurred while reading data from the client.
+ * Returns, whether the request contains more file items.
+ */
+ boolean hasNext() throws FileUploadException, IOException;
+
+ /**
+ * Return the next file item, if any.
+ * @throws FileUploadException The request could not be parsed or
+ * was otherwise invalid.
+ * @throws IOException An error occurred while reading data from the client.
+ * @throws NoSuchElementException No more file items are available.
+ * This indicates, that you didn't invoke {@link #hasNext()}, or
+ * ignored the return value "false".
+ */
+ FI next() throws FileUploadException, IOException;
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemStore.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemStore.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemStore.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,41 @@
+package org.apache.commons.fileupload2;
+
+import java.io.IOException;
+
+
+/**
+ * <p>Instances of {@link FileItemStore} are used to read
+ * file items, that are persisted. The purpose of the
+ * {@link FileItemStore} is to convert instances of
+ * {@link FileItem} into instances of {@link StoredFileItem}.</p>
+ * <p><em>Thread safety</em>: File item stores are allocating buffers
+ * for doing I/O as quickly as possible, In order to allocate these
+ * buffers only once, they are <em>not</em> thread safe, unless
+ * otherwise documented.</p>
+ */
+public abstract class FileItemStore {
+ /**
+ * Parses the given request by invoking {@link FileUpload#parse(UploadRequest)}
+ * on the given instance of {@link FileUpload}. Returns an iterator to
+ * file items, which may in fact be instances of {@link StoredFileItem}.
+ */
+ public FileItemIterator<StoredFileItem> parse(FileUpload pFileUpload, UploadRequest pRequest)
+ throws FileUploadException, IOException {
+ final FileItemIterator<FileItem> fii = pFileUpload.parse(pRequest);
+ return new FileItemIterator<StoredFileItem>(){
+ public boolean hasNext() throws FileUploadException, IOException {
+ return fii.hasNext();
+ }
+
+ public StoredFileItem next() throws FileUploadException, IOException {
+ return store(fii.next());
+ }
+ };
+ }
+
+ /**
+ * Converts the given instance of {@link FileItem} into an instance of
+ * {@link StoredFileItem}.
+ */
+ public abstract StoredFileItem store(FileItem pFileItem) throws FileUploadException, IOException;
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileItemStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileSizeMaxException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileSizeMaxException.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileSizeMaxException.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileSizeMaxException.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,73 @@
+package org.apache.commons.fileupload2;
+
+
+/**
+ * This exception is thrown, if {@link FileUpload#getFileSizeMax()}
+ * is set and the limit is exceeded.
+ */
+public class FileSizeMaxException extends FileUploadException {
+ private static final long serialVersionUID = 4888330904563531672L;
+
+ private final String fieldName;
+ private final String fileName;
+ private final long configuredMaxSize;
+ private final long actualSize;
+
+ /**
+ * Creates a new instance with the given message and cause.
+ */
+ public FileSizeMaxException(String pMessage, Throwable pCause,
+ String pFieldName, String pFileName, long pConfiguredMaxSize,
+ long pActualSize) {
+ super(pMessage, pCause);
+ configuredMaxSize = pConfiguredMaxSize;
+ actualSize = pActualSize;
+ fieldName = pFieldName;
+ fileName = pFileName;
+ }
+
+ /**
+ * Creates a new instance with the given message.
+ */
+ public FileSizeMaxException(String pMessage,
+ String pFieldName, String pFileName, long pConfiguredMaxSize,
+ long pActualSize) {
+ this (pMessage, null, pFieldName, pFileName, pConfiguredMaxSize, pActualSize);
+ }
+
+ /**
+ * Returns the configured maximum file size, which has
+ * been exceeded.
+ */
+ public long getConfiguredMaxSize() {
+ return configuredMaxSize;
+ }
+
+ /**
+ * Returns the actual file size, which is exceeding the
+ * configured maximum value. Note, that this is the number
+ * of bytes, which have been read so far, and the true file
+ * size may be even larger.
+ */
+ public long getActualSize() {
+ return actualSize;
+ }
+
+ /**
+ * Returns the field name of the file item, which caused the
+ * exception, because its size exceeded the configured maximum
+ * value.
+ */
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * Returns the file name of the file item, which caused the
+ * exception, because its size exceeded the configured maximum
+ * value. Note, that the file name may be null.
+ */
+ public String getFileName() {
+ return fileName;
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileSizeMaxException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUpload.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUpload.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUpload.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUpload.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,219 @@
+/*
+ * 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 java.io.IOException;
+
+import org.apache.commons.fileupload2.impl.FileItemIteratorImpl;
+
+
+/**
+ * <p>High level API for processing file uploads.</p>
+ *
+ * <p>This class handles multiple files per single HTML widget, sent using
+ * <code>multipart/mixed</code> encoding type, as specified by
+ * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>. Use {@link
+ * #parse(UploadRequest)} to acquire an iterator over instances of {@link
+ * org.apache.commons.fileupload2.FileItem file items} associated with a
+ * given HTML widget.</p>
+ * <p><em>Thread safety</em>: Configured instances of {@link FileUpload} are
+ * thread safe, if
+ * <ul>
+ * <li>the {@link #getEventListener() event listener} is null, or</li>
+ * <li>the {@link #getEventListener() event listener} is itself thread safe</li>
+ * </ul>
+ */
+public class FileUpload {
+ /**
+ * This constant is used to indicate, that a requests
+ * size is unlimited. This is the default value.
+ */
+ public static final long NO_REQUEST_SIZE_MAX = -1;
+
+ /**
+ * This constant is used to indicate, that a file items
+ * size is unlimited. This is the default value.
+ */
+ public static final long NO_FILE_SIZE_MAX = -1;
+
+ /**
+ * The maximum size permitted for the complete request, as opposed to
+ * {@link #fileSizeMax}. A value of {@link #NO_REQUEST_SIZE_MAX}
+ * indicates, that the request size is unlimited. This is the
+ * default.
+ */
+ private long requestSizeMax = NO_REQUEST_SIZE_MAX;
+
+ /**
+ * The maximum size permitted for a single uploaded file, as opposed
+ * to {@link #requestSizeMax}. A value of {@link #NO_FILE_SIZE_MAX}
+ * indicates, that the file size is unlimited. This is the default.
+ */
+ private long fileSizeMax = NO_FILE_SIZE_MAX;
+
+ /**
+ * The event listener to notify.
+ */
+ private EventListener listener;
+
+ /**
+ * The character encoding to use when reading the headers of an
+ * individual part. When not specified, or <code>null</code>, the request
+ * encoding is used. If that is also not specified, or <code>null</code>,
+ * then UTF-8 is used.
+ */
+ private String headerEncoding;
+
+
+ /**
+ * <p>Returns the maximum allowed size of a complete request, as opposed
+ * to {@link #getFileSizeMax()}.</p>
+ * <p>If the limit is set (in other words, if the configured value is
+ * different from {@link #NO_REQUEST_SIZE_MAX}), then the event listeners
+ * method {@link EventListener#requestSizeMaxExceeded(FileUpload, UploadRequest, long)}
+ * is invoked. The default event listener will throw a
+ * {@link RequestSizeMaxException} in that case.</p>
+ *
+ * @return The maximum allowed size, in bytes. The default value of
+ * {@link #NO_REQUEST_SIZE_MAX} indicates, that there is no limit.
+ *
+ * @see #setRequestSizeMax(long)
+ * @see #NO_REQUEST_SIZE_MAX
+ * @see EventListener#requestSizeMaxExceeded(FileUpload, UploadRequest, long)
+ * @see RequestSizeMaxException
+ */
+ public long getRequestSizeMax() {
+ return requestSizeMax;
+ }
+
+
+ /**
+ * <p>Sets the maximum allowed size of a complete request, as opposed
+ * to {@link #setFileSizeMax(long)}.</p>
+ * <p>If the limit is set (in other words, if the configured value is
+ * different from {@link #NO_REQUEST_SIZE_MAX}), then the event listeners
+ * method {@link EventListener#requestSizeMaxExceeded(FileUpload, UploadRequest, long)}
+ * is invoked. The default event listener will throw a
+ * {@link RequestSizeMaxException} in that case.</p>
+ *
+ * @param pSizeMax The maximum allowed size, in bytes. The default value of
+ * -1 indicates, that there is no limit.
+ *
+ * @see #getRequestSizeMax()
+ * @see #NO_REQUEST_SIZE_MAX
+ * @see EventListener#requestSizeMaxExceeded(FileUpload, UploadRequest, long)
+ * @see RequestSizeMaxException
+ */
+ public void setRequestSizeMax(long pSizeMax) {
+ requestSizeMax = pSizeMax;
+ }
+
+ /**
+ * <p>Returns the maximum allowed size of a single uploaded file,
+ * as opposed to {@link #getRequestSizeMax()}.</p>
+ * <p>If the limit is set (in other words, if the configured value is
+ * different from {@link #NO_FILE_SIZE_MAX}), then the event listeners
+ * method {@link EventListener#fileSizeMaxExceeded(FileUpload, UploadRequest, FileItem, long)}
+ * is invoked. The default event listener will throw a
+ * {@link FileSizeMaxException} in that case.</p>
+ *
+ * @return The maximum allowed size, in bytes. The default value of
+ * {@link #NO_FILE_SIZE_MAX} indicates, that there is no limit.
+ *
+ * @see #setFileSizeMax(long)
+ * @see #NO_FILE_SIZE_MAX
+ * @see EventListener#fileSizeMaxExceeded(FileUpload, UploadRequest, FileItem, long)
+ * @see FileSizeMaxException
+ */
+ public long getFileSizeMax() {
+ return fileSizeMax;
+ }
+
+ /**
+ * <p>Sets the maximum allowed size of a single uploaded file,
+ * as opposed to {@link #getRequestSizeMax()}.</p>
+ * <p>If the limit is set (in other words, if the configured value is
+ * different from {@link #NO_FILE_SIZE_MAX}), then the event listeners
+ * method {@link EventListener#fileSizeMaxExceeded(FileUpload, UploadRequest, FileItem, long)}
+ * is invoked. The default event listener will throw a
+ * {@link FileSizeMaxException} in that case.</p>
+ *
+ * @param pFileSizeMax The maximum allowed size, in bytes. The default value of
+ * {@link #NO_FILE_SIZE_MAX} indicates, that there is no limit.
+ *
+ * @see #getFileSizeMax()
+ * @see #NO_FILE_SIZE_MAX
+ * @see EventListener#fileSizeMaxExceeded(FileUpload, UploadRequest, FileItem, long)
+ * @see FileSizeMaxException
+ */
+ public void setFileSizeMax(long pFileSizeMax) {
+ fileSizeMax = pFileSizeMax;
+ }
+
+ /**
+ * Returns the event listener.
+ * @return The event listener, if any, or null.
+ */
+ public EventListener getEventListener() {
+ return listener;
+ }
+
+ /**
+ * Sets the event listener.
+ * @param pListener The event listener, if any. Defaults to null.
+ */
+ public void setEventListener(EventListener pListener) {
+ listener = pListener;
+ }
+
+ /**
+ * Retrieves the character encoding used when reading the headers of an
+ * individual part. When not specified, or <code>null</code>, the request
+ * encoding is used. If that is also not specified, or <code>null</code>,
+ * the platform default encoding is used.
+ *
+ * @return The encoding used to read part headers.
+ */
+ public String getHeaderEncoding() {
+ return headerEncoding;
+ }
+
+
+ /**
+ * Specifies the character encoding to be used when reading the headers of
+ * individual part. When not specified, or <code>null</code>, the request
+ * encoding is used. If that is also not specified, or <code>null</code>,
+ * the platform default encoding is used.
+ *
+ * @param encoding The encoding used to read part headers.
+ */
+ public void setHeaderEncoding(String encoding) {
+ headerEncoding = encoding;
+ }
+
+ /**
+ * Called to parse the given request.
+ * @return An instance of {@link FileItemIterator}, which allows
+ * to iterate over the file items contained in the request.
+ * @throws FileUploadException The request could not be parsed or
+ * was otherwise invalid.
+ * @throws IOException An error occurred while reading data from the client.
+ */
+ public FileItemIterator<FileItem> parse(UploadRequest pRequest) throws FileUploadException, IOException {
+ return new FileItemIteratorImpl<FileItem>(this, pRequest, getEventListener());
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUpload.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUploadException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUploadException.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUploadException.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUploadException.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,50 @@
+/*
+ * 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 java.io.IOException;
+
+
+/**
+ * Exception for errors encountered while processing the request.
+ */
+public class FileUploadException extends IOException {
+ private static final long serialVersionUID = 5995919789504988633L;
+
+ /**
+ * Constructs a new <code>FileUploadException</code> with specified detail
+ * message.
+ *
+ * @param pMessage the error message.
+ */
+ public FileUploadException(final String pMessage) {
+ this(pMessage, null);
+ }
+
+ /**
+ * Creates a new <code>FileUploadException</code> with the given
+ * detail message and cause.
+ * @param pMessage The exceptions detail message.
+ * @param pCause The exceptions cause.
+ */
+ public FileUploadException(String pMessage, Throwable pCause) {
+ super(pMessage);
+ if (pCause != null) {
+ initCause(pCause);
+ }
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/FileUploadException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/InvalidContentTypeException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/InvalidContentTypeException.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/InvalidContentTypeException.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/InvalidContentTypeException.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,21 @@
+package org.apache.commons.fileupload2;
+
+
+/**
+ * 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 an <code>InvalidContentTypeException</code> with
+ * the specified detail message.
+ *
+ * @param message The detail message.
+ */
+ public InvalidContentTypeException(String message) {
+ super(message);
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/InvalidContentTypeException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/RequestSizeMaxException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/RequestSizeMaxException.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/RequestSizeMaxException.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/RequestSizeMaxException.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,49 @@
+package org.apache.commons.fileupload2;
+
+
+/**
+ * This exception is thrown, if {@link FileUpload#getRequestSizeMax()}
+ * is set and the limit is exceeded.
+ */
+public class RequestSizeMaxException extends FileUploadException {
+ private static final long serialVersionUID = 4888330904563531672L;
+
+ private final long configuredMaxSize;
+ private final long actualSize;
+
+ /**
+ * Creates a new instance with the given message and cause.
+ */
+ public RequestSizeMaxException(String pMessage, Throwable pCause, long pConfiguredMaxSize, long pActualSize) {
+ super(pMessage, pCause);
+ configuredMaxSize = pConfiguredMaxSize;
+ actualSize = pActualSize;
+ }
+
+ /**
+ * Creates a new instance with the given message.
+ */
+ public RequestSizeMaxException(String pMessage, long pConfiguredMaxSize, long pActualSize) {
+ super(pMessage);
+ configuredMaxSize = pConfiguredMaxSize;
+ actualSize = pActualSize;
+ }
+
+ /**
+ * Returns the configured maximum request size, which has
+ * been exceeded.
+ */
+ public long getConfiguredMaxSize() {
+ return configuredMaxSize;
+ }
+
+ /**
+ * Returns the actual request size, which is exceeding the
+ * configured maximum value. Note, that this is the number
+ * of bytes, which have been read so far, and the true request
+ * size may be even larger.
+ */
+ public long getActualSize() {
+ return actualSize;
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/RequestSizeMaxException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/StoredFileItem.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/StoredFileItem.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/StoredFileItem.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/StoredFileItem.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,79 @@
+package org.apache.commons.fileupload2;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+
+/**
+ * A {@link StoredFileItem} is a persistent {@link FileItem}.
+ * The main difference to the latter is that you may invoke
+ * {@link StoredFileItem#getInputStream()}, or
+ * {@link StoredFileItem#getReader(String)}, repeatedly.
+ * Additionally, the {@link StoredFileItem} guarantees, that
+ * {@link StoredFileItem#getContentLength()} will never return
+ * the value FileItem#UNKNOWN_CONTENT_LENGTH.
+ */
+public interface StoredFileItem extends FileItem {
+ /**
+ * Returns the size of the file item. Unlike {@link FileItem#getContentLength()},
+ * this method will never return the value {@link UploadRequest#UNKNOWN_CONTENT_LENGTH}.
+ * @return The size of the file item, in bytes.
+ * @see FileItem#getContentLength()
+ */
+ long getContentLength();
+
+ /**
+ * <p>Returns an {@link java.io.InputStream InputStream} that can be
+ * used to retrieve the contents of the file item.</p>
+ * <p><em>Note</em>: Unlike
+ * {@link FileItem#getInputStream()}, you may invoke this method
+ * repeatedly or in parallel with {@link StoredFileItem#getReader(String)}.</p>
+ *
+ * @return An {@link java.io.InputStream InputStream} that can be
+ * used to retrieve the contents of the file item.
+ *
+ * @throws FileUploadException The file item stream could not be parsed,
+ * or was otherwise invalid.
+ * @throws IOException An I/O error occurred while reading the underlying
+ * data stream.
+ * @see FileItem#getInputStream()
+ * @see #getReader(String)
+ */
+ InputStream getInputStream() throws FileUploadException, IOException;
+
+ /**
+ * <p>Returns the contents of the file item as a reader, using the
+ * specified encoding.</p>
+ * <p><em>Note</em>: Unlike
+ * {@link FileItem#getReader(String)}, you may invoke this method
+ * repeatedly or in parallel with {@link StoredFileItem#getInputStream()}.</p>
+ *
+ * @param pEncoding The character encoding to use for conversion of
+ * bytes into characters.
+ * @return An {@link java.io.Reader Reader} that can be
+ * used to retrieve the contents of the file item.
+ *
+ * @throws FileUploadException The file item stream could not be parsed,
+ * or was otherwise invalid.
+ * @throws UnsupportedEncodingException The given encoding is not supported.
+ * @throws IOException An I/O error occurred while reading the underlying
+ * data stream.
+ *
+ * @see FileItem#getReader(String)
+ * @see #getReader(String)
+ * @see #getEncoding()
+ */
+ Reader getReader(String pEncoding)
+ throws FileUploadException, UnsupportedEncodingException, IOException;
+
+ /**
+ * Frees all resources, which are allocated by the {@link StoredFileItem
+ * file item}. As a consequence, it is no longer valid to invoke
+ * {@link #getInputStream()}, or {@link #getReader(String)}.
+ * @throws FileUploadException Deleting the file item failed.
+ * @throws IOException An I/O error occurred while deleting the file item.
+ */
+ void delete() throws FileUploadException, IOException;
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/StoredFileItem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/UploadRequest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/UploadRequest.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/UploadRequest.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/UploadRequest.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,49 @@
+package org.apache.commons.fileupload2;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+
+/**
+ * Interface of an request, which may be processed by instances
+ * of {@link FileUpload}.
+ */
+public interface UploadRequest {
+ /**
+ * This value, if returned by {@link #getContentLength()}, indicates
+ * that the file items content length is unknown.
+ */
+ public static final long UNKNOWN_CONTENT_LENGTH = -1;
+
+ /**
+ * Retrieve the character encoding for the request.
+ *
+ * @return The character encoding for the request.
+ */
+ String getCharacterEncoding();
+
+ /**
+ * Retrieve the content type of the request.
+ *
+ * @return The content type of the request.
+ */
+ String getContentType();
+
+ /**
+ * Retrieve the content length of the request, if known, or
+ * {@link #UNKNOWN_CONTENT_LENGTH}.
+ *
+ * @return The content length of the request, if known, or
+ * {@link #UNKNOWN_CONTENT_LENGTH}.
+ */
+ long getContentLength();
+
+ /**
+ * Retrieve the input stream for the request.
+ *
+ * @return The input stream for the request.
+ *
+ * @throws IOException if a problem occurs.
+ */
+ InputStream getInputStream() throws IOException;
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/UploadRequest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItem.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItem.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItem.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,64 @@
+package org.apache.commons.fileupload2.disk;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.fileupload2.FileItem;
+import org.apache.commons.fileupload2.FileUploadException;
+import org.apache.commons.fileupload2.StoredFileItem;
+import org.apache.commons.fileupload2.impl.AbstractStoredFileItem;
+import org.apache.commons.fileupload2.impl.WritableFileItem;
+
+
+/**
+ * Implementation of {@link StoredFileItem} for file items,
+ * which are stored in a file.
+ */
+public class DiskFileItem extends AbstractStoredFileItem implements WritableFileItem {
+ private static final long serialVersionUID = -4965116228189371571L;
+
+ private File file;
+
+ /**
+ * Creates a new instance with default settings.
+ */
+ @SuppressWarnings("unused")
+ private DiskFileItem() {
+ // Nothing to do
+ }
+
+ /**
+ * Creates a new instance.
+ */
+ public DiskFileItem(FileItem pFileItem, File pFile) {
+ super(pFileItem);
+ if (pFile == null) {
+ throw new IllegalArgumentException("The temporary file must not be null.");
+ }
+ file = pFile;
+ }
+
+ public InputStream getInputStream() throws FileUploadException, IOException {
+ return new FileInputStream(file);
+ }
+
+ /**
+ * Returns the temporary file, which contains the file items contents.
+ */
+ public File getFile() {
+ return file;
+ }
+
+ public OutputStream newOutputStream() throws IOException {
+ return new FileOutputStream(getFile());
+ }
+
+ public void delete() throws FileUploadException, IOException {
+ file.delete();
+ file = null;
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItemStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItemStore.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItemStore.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItemStore.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,76 @@
+package org.apache.commons.fileupload2.disk;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.fileupload2.FileItem;
+import org.apache.commons.fileupload2.FileItemStore;
+import org.apache.commons.fileupload2.FileUploadException;
+import org.apache.commons.fileupload2.impl.MemoryCapableFileItemStore;
+import org.apache.commons.fileupload2.impl.WritableFileItem;
+
+
+/**
+ * <p>Implementation of {@link FileItemStore}, which saves
+ * file items on the disk.</p>
+ */
+public class DiskFileItemStore extends MemoryCapableFileItemStore {
+ private File repository;
+ private boolean deletingOnExit = true;
+
+ /**
+ * Returns, whether the file item store will invoke
+ * {@link File#deleteOnExit()} on the temporary files returned
+ * by {@link #newFile()}.
+ */
+ public boolean isDeletingOnExit() {
+ return deletingOnExit;
+ }
+
+ /**
+ * Sets, whether the file item store will invoke
+ * {@link File#deleteOnExit()} on the temporary files returned
+ * by {@link #newFile()}.
+ */
+ public void setDeletingOnExit(boolean pDeletingOnExit) {
+ deletingOnExit = pDeletingOnExit;
+ }
+
+ /**
+ * Returns the directory used to temporarily store files that are larger
+ * than the configured size threshold.
+ *
+ * @return The directory in which temporary files will be located.
+ *
+ * @see #setRepository(java.io.File)
+ *
+ */
+ public File getRepository() {
+ return repository;
+ }
+
+ /**
+ * Sets the directory used to temporarily store files that are larger
+ * than the configured size threshold.
+ *
+ * @param pRepository The directory in which temporary files will be located.
+ *
+ * @see #getRepository()
+ *
+ */
+ public void setRepository(File pRepository) {
+ repository = pRepository;
+ }
+
+ protected File newFile() throws IOException {
+ final File f = File.createTempFile("fileUpload", null, getRepository());
+ f.deleteOnExit();
+ return f;
+ }
+
+ @Override
+ protected WritableFileItem newWritableFileItem(FileItem pFileItem)
+ throws FileUploadException, IOException {
+ return new DiskFileItem(pFileItem, newFile());
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/DiskFileItemStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/TrackingDiskFileItemStore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/TrackingDiskFileItemStore.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/TrackingDiskFileItemStore.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/TrackingDiskFileItemStore.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,54 @@
+package org.apache.commons.fileupload2.disk;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.fileupload2.FileItem;
+import org.apache.commons.fileupload2.FileUploadException;
+import org.apache.commons.fileupload2.impl.WritableFileItem;
+import org.apache.commons.io.FileCleaningTracker;
+
+
+/**
+ * A subclass of {@link DiskFileItemStore}, which spawns a thread
+ * for reaping temporary files.
+ */
+public class TrackingDiskFileItemStore extends DiskFileItemStore {
+ private FileCleaningTracker tracker;
+
+ /**
+ * Returns the {@link FileCleaningTracker}, if any. If such
+ * a tracker is present (in other words, if this method
+ * returns another value than null), then the method
+ * {@link #newWritableFileItem(org.apache.commons.fileupload2.FileItem)}
+ * will pass the temporary file that it has created to
+ * {@link FileCleaningTracker#track(java.io.File, Object)}.
+ */
+ public FileCleaningTracker getTracker() {
+ return tracker;
+ }
+
+ /**
+ * Sets the {@link FileCleaningTracker}, if any. If such
+ * a tracker is present (in other words, if the parameter
+ * {@code pTracker} contains another value than null), then the method
+ * {@link #newWritableFileItem(org.apache.commons.fileupload2.FileItem)}
+ * will pass the temporary file that it has created to
+ * {@link FileCleaningTracker#track(java.io.File, Object)}.
+ */
+ public void setTracker(FileCleaningTracker pTracker) {
+ tracker = pTracker;
+ }
+
+ @Override
+ protected WritableFileItem newWritableFileItem(FileItem pFileItem)
+ throws FileUploadException, IOException {
+ final WritableFileItem wfi = super.newWritableFileItem(pFileItem);
+ final FileCleaningTracker fct = getTracker();
+ if (fct != null && wfi instanceof DiskFileItem) {
+ final File f = ((DiskFileItem) wfi).getFile();
+ fct.track(f, wfi);
+ }
+ return wfi;
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/disk/TrackingDiskFileItemStore.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/impl/AbstractFileItem.java
URL: http://svn.apache.org/viewvc/commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/impl/AbstractFileItem.java?rev=951978&view=auto
==============================================================================
--- commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/impl/AbstractFileItem.java (added)
+++ commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/impl/AbstractFileItem.java Sun Jun 6 21:19:54 2010
@@ -0,0 +1,105 @@
+package org.apache.commons.fileupload2.impl;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.fileupload2.FileItem;
+import org.apache.commons.fileupload2.FileUploadException;
+
+
+/**
+ * Abstract base implementation of {@link FileItem}.
+ */
+public abstract class AbstractFileItem implements FileItem {
+ private long contentLength;
+ private String contentType, encoding;
+ private String fieldName, fileName;
+ private boolean formField;
+
+ /**
+ * Creates a new instance with default settings.
+ */
+ protected AbstractFileItem() {
+ // Nothing to do.
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ /**
+ * Sets the file items content length.
+ */
+ public void setContentLength(long pContentLength) {
+ contentLength = pContentLength;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * Sets the content type.
+ * @see #getContentType()
+ */
+ public void setContentType(String pContentType) {
+ contentType = pContentType;
+ }
+
+ public String getEncoding() {
+ return encoding;
+ }
+
+ /**
+ * Sets the file items encoding.
+ */
+ public void setEncoding(String pEncoding) {
+ encoding = pEncoding;
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * Sets the field name.
+ * @see #getFieldName()
+ */
+ public void setFieldName(String pFieldName) {
+ fieldName = pFieldName;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ /**
+ * Sets the file name.
+ * @see #getFileName()
+ */
+ public void setFileName(String pFileName) {
+ fileName = pFileName;
+ }
+
+ public boolean isFormField() {
+ return formField;
+ }
+
+ /**
+ * Sets, whether the file item is in fact a simple form field.
+ * If the file item is no simple form field, then the value
+ * returned by {@link #getFileName()} is valid. Otherwise, the
+ * value returned by {@link #getFileName()} will most likely be
+ * null, and should be ignored.
+ */
+ public void setFormField(boolean pFormField) {
+ formField = pFormField;
+ }
+
+ public Reader getReader(String pEncoding) throws FileUploadException,
+ UnsupportedEncodingException, IOException {
+ return new InputStreamReader(getInputStream(), pEncoding);
+ }
+}
Propchange: commons/sandbox/commons-fileupload2/src/java/org/apache/commons/fileupload2/impl/AbstractFileItem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain