commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcna...@apache.org
Subject cvs commit: jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload DefaultFileItem.java FileUpload.java
Date Thu, 06 Jun 2002 23:59:29 GMT
jmcnally    2002/06/06 16:59:29

  Modified:    fileupload/src/java/org/apache/commons/fileupload
                        DefaultFileItem.java FileUpload.java
  Log:
  reverting change to apply url decoding to the headers and form data.
  
  also allowing all options to be set in within a single method call to parse the
  request.  This could be useful if different requests would be stored in
  different locations or have different a different maximum allowable size.
  
  Revision  Changes    Path
  1.6       +1 -7      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultFileItem.java	18 Apr 2002 16:10:28 -0000	1.5
  +++ DefaultFileItem.java	6 Jun 2002 23:59:29 -0000	1.6
  @@ -54,7 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.net.URLDecoder;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.BufferedInputStream;
  @@ -92,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.5 2002/04/18 16:10:28 jmcnally Exp $
  + * @version $Id: DefaultFileItem.java,v 1.6 2002/06/06 23:59:29 jmcnally Exp $
    */
   public class DefaultFileItem
       implements FileItem
  @@ -250,11 +249,6 @@
                   byteStream = null;
               }
           }
  -        if (isFormField()) 
  -        {
  -            // client may have encoded the parameter
  -            content = URLDecoder.decode(new String(content)).getBytes();
  -        }        
   
           return content;
       }
  
  
  
  1.4       +24 -15    jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/FileUpload.java
  
  Index: FileUpload.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/FileUpload.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileUpload.java	18 Apr 2002 16:10:28 -0000	1.3
  +++ FileUpload.java	6 Jun 2002 23:59:29 -0000	1.4
  @@ -54,7 +54,6 @@
    * <http://www.apache.org/>.
    */
   
  -import java.net.URLDecoder;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
  @@ -88,7 +87,7 @@
    * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id: FileUpload.java,v 1.3 2002/04/18 16:10:28 jmcnally Exp $
  + * @version $Id: FileUpload.java,v 1.4 2002/06/06 23:59:29 jmcnally Exp $
    */
   public class FileUpload
   {
  @@ -115,7 +114,7 @@
       /**
        * Part of HTTP header.
        */
  -    public static final String MULTIPART =
  +    private static final String MULTIPART =
           "multipart/";
   
       /**
  @@ -152,7 +151,8 @@
       public List parseRequest(HttpServletRequest req)
           throws FileUploadException
       {
  -        return parseRequest(req, getRepositoryPath());
  +        return parseRequest(req, getSizeThreshold(), getSizeMax(), 
  +                            getRepositoryPath());
       }
   
       /**
  @@ -160,11 +160,14 @@
        * compliant <code>multipart/form-data</code> stream.
        *
        * @param req The servlet request to be parsed.
  +     * @param sizeThreshold the max size in bytes to be stored in memory
  +     * @param sizeMax the maximum allowed upload size in bytes
        * @param path The location where the files should be stored.
        * @exception FileUploadException If there are problems reading/parsing
        * the request or storing files.
        */
  -    public List parseRequest(HttpServletRequest req, String path)
  +    public List parseRequest(HttpServletRequest req, int sizeThreshold, 
  +                             int sizeMax, String path)
           throws FileUploadException
       {
           ArrayList items = new ArrayList();
  @@ -183,7 +186,7 @@
                   "it's size is unknown");
           }
   
  -        if(getSizeMax() >= 0 && requestSize > getSizeMax())
  +        if(sizeMax >= 0 && requestSize > sizeMax)
           {
               throw new FileUploadException("the request was rejected because " +
                   "it's size exceeds allowed range");
  @@ -220,8 +223,9 @@
                               headers = parseHeaders(multi.readHeaders());
                               if (getFileName(headers) != null)
                               {
  -                                FileItem item = createItem(path, headers,
  -                                                           requestSize);
  +                                FileItem item = 
  +                                    createItem(sizeThreshold, path,
  +                                               headers, requestSize);
                                   OutputStream os = 
                                       ((DefaultFileItem)item).getOutputStream();
                                   try
  @@ -250,7 +254,8 @@
                           if (getFileName(headers) != null)
                           {
                               // A single file.
  -                            FileItem item = createItem(path, headers,
  +                            FileItem item = createItem(sizeThreshold, 
  +                                                       path, headers,
                                                          requestSize);
                               OutputStream os = 
                                   ((DefaultFileItem)item).getOutputStream();
  @@ -268,7 +273,8 @@
                           else
                           {
                               // A form field.
  -                            FileItem item = createItem(path, headers,
  +                            FileItem item = createItem(sizeThreshold,
  +                                                       path, headers,
                                                          requestSize);
                               OutputStream os = 
                                   ((DefaultFileItem)item).getOutputStream();
  @@ -325,9 +331,9 @@
                   {
                       fileName = str;
                   }
  -            }
  +            }            
           }
  -        return URLDecoder.decode(fileName);
  +        return fileName;
       }
   
       /**
  @@ -349,7 +355,7 @@
                   fieldName = cd.substring(start + 6, end);
               }
           }
  -        return URLDecoder.decode(fieldName);
  +        return fieldName;
       }
   
       /**
  @@ -361,12 +367,13 @@
        * @param requestSize The size of the request.
        * @return A newly created <code>FileItem</code>.
        */
  -    protected FileItem createItem( String path,
  +    protected FileItem createItem( int sizeThreshold, 
  +                                   String path,
                                      Map headers,
                                      int requestSize )
       {
           return DefaultFileItem.newInstance(path, getFileName(headers),
  -            getHeader(headers, CONTENT_TYPE), requestSize, getSizeThreshold());
  +            getHeader(headers, CONTENT_TYPE), requestSize, sizeThreshold);
       }
   
       /**
  @@ -474,6 +481,7 @@
   
       /**
        * The threshold beyond which files are written directly to disk.
  +     * Default is 1024 bytes.
        */
       public int getSizeThreshold()
       {
  @@ -483,6 +491,7 @@
       
       /**
        * The threshold beyond which files are written directly to disk.
  +     * Default is 1024 bytes.
        */
       public void setSizeThreshold(int  v) 
       {
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message