You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jm...@apache.org on 2002/04/11 08:03:20 UTC

cvs commit: jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload package.html DefaultFileItem.java FileUploadException.java MultipartStream.java

jmcnally    02/04/10 23:03:20

  Modified:    fileupload/src/java/org/apache/commons/fileupload
                        DefaultFileItem.java FileUploadException.java
                        MultipartStream.java
  Added:       fileupload/src/java/org/apache/commons/fileupload
                        package.html
  Log:
  javadoc changes and added  example usage in a package.html
  
  Revision  Changes    Path
  1.4       +3 -3      jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/DefaultFileItem.java
  
  Index: DefaultFileItem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/DefaultFileItem.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultFileItem.java	9 Apr 2002 17:33:53 -0000	1.3
  +++ DefaultFileItem.java	11 Apr 2002 06:03:19 -0000	1.4
  @@ -70,8 +70,8 @@
   import javax.activation.DataSource;
   
   /**
  - * <p> This class represents a file that was received by Turbine using
  - * <code>multipart/form-data</code> POST request.
  + * <p> The implementation of 
  + * {@link org.apache.commons.fileupload.FileItem FileItem} interface.
    *
    * <p> After retrieving an instance of this class from the {@link
    * org.apache.commons.fileupload.FileUpload FileUpload} (see
  @@ -91,7 +91,7 @@
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
  - * @version $Id: DefaultFileItem.java,v 1.3 2002/04/09 17:33:53 jmcnally Exp $
  + * @version $Id: DefaultFileItem.java,v 1.4 2002/04/11 06:03:19 jmcnally Exp $
    */
   public class DefaultFileItem
       implements FileItem
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/FileUploadException.java
  
  Index: FileUploadException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/FileUploadException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FileUploadException.java	24 Mar 2002 07:05:13 -0000	1.1
  +++ FileUploadException.java	11 Apr 2002 06:03:19 -0000	1.2
  @@ -55,10 +55,10 @@
    */
   
   /**
  - * The base class of all exceptions thrown by FileUpload.
  + * Exception for errors encountered processing the request.
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id: FileUploadException.java,v 1.1 2002/03/24 07:05:13 jmcnally Exp $
  + * @version $Id: FileUploadException.java,v 1.2 2002/04/11 06:03:19 jmcnally Exp $
    */
   public class FileUploadException
       extends Exception
  
  
  
  1.2       +5 -3      jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/MultipartStream.java
  
  Index: MultipartStream.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/MultipartStream.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MultipartStream.java	24 Mar 2002 07:05:13 -0000	1.1
  +++ MultipartStream.java	11 Apr 2002 06:03:19 -0000	1.2
  @@ -59,9 +59,11 @@
   import java.io.OutputStream;
   
   /**
  + * <p>Low level api for processing file uploads.
  + *
    * This class can be used to process data streams conforming to MIME
  - * 'multipart' format as defined in <a
  - * href="http://rf.cs/rfc1521.html">RFC&nbsp;1251</a>.  Arbitrary
  + * 'multipart' format as defined in
  + * <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>.  Arbitrary
    * large amouns of data in the stream can be processed under constant
    * memory usage.
    *
  @@ -112,7 +114,7 @@
    * </pre>
    *
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
  - * @version $Id: MultipartStream.java,v 1.1 2002/03/24 07:05:13 jmcnally Exp $
  + * @version $Id: MultipartStream.java,v 1.2 2002/04/11 06:03:19 jmcnally Exp $
    */
   public class MultipartStream
   {
  
  
  
  1.1                  jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/package.html
  
  Index: package.html
  ===================================================================
  <!-- $Id: package.html,v 1.1 2002/04/11 06:03:19 jmcnally Exp $ -->
  <html>
     <head>
        <title>Overview of the org.apache.commons.fileupload component</title>
     </head>
     <body>
        <p>
           Component for handling html file uploads as given by rfc 1867 
           <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC&nbsp;1867</a>.
        </p>
        <p>
           Normal usage of the package involves 
           {@link org.apache.commons.fileupload.FileUpload FileUpload} 
           parsing the HttpServletRequest and returning a list of
           {@link org.apache.commons.fileupload.FileItem FileItem}'s.
           These <code>FileItem</code>'s provide easy access to the data
           given in the upload.  There is also a low level api for
           manipulating the upload data encapsulated in the 
           {@link org.apache.commons.fileupload.MultipartStream MultipartStream} 
           class. 
        </p> 
   
        <p>
           Normal usage example:
        </p>
  <pre>
  
      public void doPost(HttpServletRequest req, HttpServletResponse res)
      {
          FileUpload fu = new FileUpload();
          // maximum size before a FileUploadException will be thrown
          fu.setSizeMax(1000000);
          // maximum size that will be stored in memory
          fu.setSizeThreshold(4096);
          // the location for saving data that is larger than getSizeThreshold()
          fu.setRepositoryPath("/tmp");
  
          List fileItems = fu.parseRequest(req);
          // assume we know there are two files. The first file is a small 
          // text file, the second is unknown and is written to a file on
          // the server 
          Iterator i = fileItems.iterator();
          String comment = ((FileItem)i.next()).getString();
          FileItem fi = (FileItem)i.next();
          // filename on the client
          String fileName = fi.getFileName();
          // save comment and filename to database
          ...
          // write the file
          fi.write("/www/uploads/" + fileName);
      }
  </pre>
        <p>
           In the example above the first file is loaded into memory as a 
           <code>String</code>. Before calling the getString method, the data
           may have been in memory or on disk depending on its size.  The second
           file we assume it will be large and therefore never explicitly load
           it into memory, though if it is less than 4096 bytes it will be
           in memory before it is written to its final location.  When writing to
           the final location, if the data is larger than the 
           threshold, an attempt is made to rename the temporary file to
           the given location.  If it cannot be renamed, it is streamed to the
           new location.
        </p>
     </body>
  </html>
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>