commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mart...@apache.org
Subject cvs commit: jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload DefaultFileItem.java FileItem.java FileUpload.java FileUploadException.java MultipartStream.java
Date Thu, 22 Aug 2002 04:26:48 GMT
martinc     2002/08/21 21:26:48

  Modified:    fileupload/src/java/org/apache/commons/fileupload
                        DefaultFileItem.java FileItem.java FileUpload.java
                        FileUploadException.java MultipartStream.java
  Log:
  Revert stylistic changes, going back to Turbine coding conventions.
  
  Revision  Changes    Path
  1.12      +130 -59   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.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- DefaultFileItem.java	18 Aug 2002 06:09:21 -0000	1.11
  +++ DefaultFileItem.java	22 Aug 2002 04:26:47 -0000	1.12
  @@ -85,9 +85,9 @@
    * {@link org.apache.commons.fileupload.FileUpload
    * #parseRequest(javax.servlet.http.HttpServletRequest)}), you may
    * either request all contents of file at once using {@link #get()} or
  - * request an {@link java.io.InputStream InputStream} with
  - * {@link #getInputStream()} and process the file without attempting to load
  - * it into memory, which may come in handy with large files.
  + * request an {@link java.io.InputStream InputStream} with {@link #getInputStream()}
  + * and process the file without attempting to load it into memory, which
  + * may come handy with large files.
    *
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
  @@ -95,9 +95,11 @@
    * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Revision$ $Date$
  + * @version $Id$
    */
  -public class DefaultFileItem implements FileItem {
  +public class DefaultFileItem
  +    implements FileItem
  +{
   
       // ----------------------------------------------------------- Data members
   
  @@ -157,7 +159,8 @@
       /**
        * Default constructor.
        */
  -    public DefaultFileItem() {
  +    public DefaultFileItem()
  +    {
       }
   
   
  @@ -171,7 +174,8 @@
        * @param contentType The content type passed by the browser or
        * <code>null</code> if not defined.
        */
  -    protected DefaultFileItem(String fileName, String contentType) {
  +    protected DefaultFileItem(String fileName, String contentType)
  +    {
           this.fileName = fileName;
           this.contentType = contentType;
       }
  @@ -189,11 +193,17 @@
        *
        * @exception IOException if an error occurs.
        */
  -    public InputStream getInputStream() throws IOException {
  -        if (content == null) {
  -            if (storeLocation != null) {
  +    public InputStream getInputStream()
  +        throws IOException
  +    {
  +        if (content == null)
  +        {
  +            if (storeLocation != null)
  +            {
                   return new FileInputStream(storeLocation);
  -            } else {
  +            }
  +            else
  +            {
                   content = byteStream.toByteArray();
                   byteStream = null;
               }
  @@ -209,7 +219,8 @@
        * @return The content type passed by the browser or <code>null</code> if
        *         not defined.
        */
  -    public String getContentType() {
  +    public String getContentType()
  +    {
           return contentType;
       }
   
  @@ -219,7 +230,8 @@
        *
        * @return The original filename in the client's filesystem.
        */
  -    public String getName() {
  +    public String getName()
  +    {
           return fileName;
       }
   
  @@ -234,7 +246,8 @@
        * @return <code>true</code> if the file contents will be read
        *         from memory.
        */
  -    public boolean isInMemory() {
  +    public boolean isInMemory()
  +    {
           return (content != null || byteStream != null);
       }
   
  @@ -244,12 +257,18 @@
        *
        * @return The size of the file, in bytes.
        */
  -    public long getSize() {
  -        if (storeLocation != null) {
  +    public long getSize()
  +    {
  +        if (storeLocation != null)
  +        {
               return storeLocation.length();
  -        } else if (byteStream != null) {
  +        }
  +        else if (byteStream != null)
  +        {
               return byteStream.size();
  -        } else {
  +        }
  +        else
  +        {
               return content.length;
           }
       }
  @@ -262,17 +281,25 @@
        *
        * @return The contents of the file as an array of bytes.
        */
  -    public byte[] get() {
  -        if (content == null) {
  -            if (storeLocation != null) {
  +    public byte[] get()
  +    {
  +        if (content == null)
  +        {
  +            if (storeLocation != null)
  +            {
                   content = new byte[(int) getSize()];
  -                try {
  +                try
  +                {
                       FileInputStream fis = new FileInputStream(storeLocation);
                       fis.read(content);
  -                } catch (Exception e) {
  +                }
  +                catch (Exception e)
  +                {
                       content = null;
                   }
  -            } else {
  +            }
  +            else
  +            {
                   content = byteStream.toByteArray();
                   byteStream = null;
               }
  @@ -295,7 +322,8 @@
        *                                         encoding is not available.
        */
       public String getString(String encoding)
  -            throws UnsupportedEncodingException {
  +        throws UnsupportedEncodingException
  +    {
           return new String(get(), encoding);
       }
   
  @@ -307,7 +335,8 @@
        *
        * @return The contents of the file, as a string.
        */
  -    public String getString() {
  +    public String getString()
  +    {
           return new String(get());
       }
   
  @@ -325,7 +354,8 @@
        * @return The data file, or <code>null</code> if the data is stored in
        *         memory.
        */
  -    public File getStoreLocation() {
  +    public File getStoreLocation()
  +    {
           return storeLocation;
       }
   
  @@ -341,49 +371,70 @@
        *
        * @exception Exception if an error occurs.
        */
  -    public void write(String file) throws Exception {
  -        if (isInMemory()) {
  +    public void write(String file) throws Exception
  +    {
  +        if (isInMemory())
  +        {
               FileOutputStream fout = null;
  -            try {
  +            try
  +            {
                   fout = new FileOutputStream(file);
                   fout.write(get());
  -            } finally {
  -                if (fout != null) {
  +            }
  +            finally
  +            {
  +                if (fout != null)
  +                {
                       fout.close();
                   }
               }
  -        } else if (storeLocation != null) {
  +        }
  +        else if (storeLocation != null)
  +        {
               /*
                * The uploaded file is being stored on disk
                * in a temporary location so move it to the
                * desired file.
                */
  -            if (storeLocation.renameTo(new File(file)) == false) {
  +            if (storeLocation.renameTo(new File(file)) == false)
  +            {
                   BufferedInputStream in = null;
                   BufferedOutputStream out = null;
  -                try {
  +                try
  +                {
                       in = new BufferedInputStream(
                           new FileInputStream(storeLocation));
                       out = new BufferedOutputStream(new FileOutputStream(file));
                       byte[] bytes = new byte[2048];
                       int s = 0;
  -                    while ((s = in.read(bytes)) != -1) {
  +                    while ((s = in.read(bytes)) != -1)
  +                    {
                           out.write(bytes, 0, s);
                       }
  -                } finally {
  -                    try {
  +                }
  +                finally
  +                {
  +                    try
  +                    {
                           in.close();
  -                    } catch (Exception e) {
  +                    }
  +                    catch (Exception e)
  +                    {
                           // ignore
                       }
  -                    try {
  +                    try
  +                    {
                           out.close();
  -                    } catch (Exception e) {
  +                    }
  +                    catch (Exception e)
  +                    {
                           // ignore
                       }
                   }
               }
  -        } else {
  +        }
  +        else
  +        {
               /*
                * For whatever reason we cannot write the
                * file to disk.
  @@ -401,10 +452,12 @@
        * collected, this method can be used to ensure that this is done at an
        * earlier time, thus preserving system resources.
        */
  -    public void delete() {
  +    public void delete()
  +    {
           byteStream = null;
           content = null;
  -        if (storeLocation != null && storeLocation.exists()) {
  +        if (storeLocation != null && storeLocation.exists())
  +        {
               storeLocation.delete();
           }
       }
  @@ -416,7 +469,8 @@
        *
        * @return The name of the form field.
        */
  -    public String getFieldName() {
  +    public String getFieldName()
  +    {
           return fieldName;
       }
   
  @@ -426,7 +480,8 @@
        *
        * @param fieldName The name of the form field.
        */
  -    public void setFieldName(String fieldName) {
  +    public void setFieldName(String fieldName)
  +    {
           this.fieldName = fieldName;
       }
   
  @@ -438,7 +493,8 @@
        * @return <code>true</code> if the instance represents a simple form
        *         field; <code>false</code> if it represents an uploaded file.
        */
  -    public boolean isFormField() {
  +    public boolean isFormField()
  +    {
           return isFormField;
       }
   
  @@ -450,7 +506,8 @@
        * @param state <code>true</code> if the instance represents a simple form
        *              field; <code>false</code> if it represents an uploaded file.
        */
  -    public void setIsFormField(boolean state) {
  +    public void setIsFormField(boolean state)
  +    {
           isFormField = state;
       }
   
  @@ -461,8 +518,10 @@
       /**
        * Removes the file contents from the temporary storage.
        */
  -    protected void finalize() {
  -        if (storeLocation != null && storeLocation.exists()) {
  +    protected void finalize()
  +    {
  +        if (storeLocation != null && storeLocation.exists())
  +        {
               storeLocation.delete();
           }
       }
  @@ -477,10 +536,15 @@
        *
        * @exception IOException if an error occurs.
        */
  -    public OutputStream getOutputStream() throws IOException {
  -        if (storeLocation == null) {
  +    public OutputStream getOutputStream()
  +        throws IOException
  +    {
  +        if (storeLocation == null)
  +        {
               return byteStream;
  -        } else {
  +        }
  +        else
  +        {
               return new FileOutputStream(storeLocation);
           }
       }
  @@ -505,16 +569,20 @@
                                          String name,
                                          String contentType,
                                          int requestSize,
  -                                       int threshold) {
  +                                       int threshold)
  +    {
           DefaultFileItem item = new DefaultFileItem(name, contentType);
  -        if (requestSize > threshold) {
  +        if (requestSize > threshold)
  +        {
               String fileName = getUniqueId();
               fileName = "upload_" + fileName + ".tmp";
               fileName = path + "/" + fileName;
               File f = new File(fileName);
               f.deleteOnExit();
               item.storeLocation = f;
  -        } else {
  +        }
  +        else
  +        {
               item.byteStream = new ByteArrayOutputStream();
           }
           return item;
  @@ -530,16 +598,19 @@
        *
        * @return A String with the non-random looking instance identifier.
        */
  -    private static String getUniqueId() {
  +    private static String getUniqueId()
  +    {
           int current;
  -        synchronized (DefaultFileItem.class) {
  +        synchronized (DefaultFileItem.class)
  +        {
               current = counter++;
           }
           String id = Integer.toString(current);
   
           // If you manage to get more than 100 million of ids, you'll
           // start getting ids longer than 8 characters.
  -        if (current < 100000000) {
  +        if (current < 100000000)
  +        {
               id = ("00000000" + id).substring(id.length());
           }
           return id;
  
  
  
  1.8       +6 -5      jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/FileItem.java
  
  Index: FileItem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/fileupload/src/java/org/apache/commons/fileupload/FileItem.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FileItem.java	18 Aug 2002 06:09:21 -0000	1.7
  +++ FileItem.java	22 Aug 2002 04:26:47 -0000	1.8
  @@ -78,9 +78,9 @@
    * {@link org.apache.commons.fileupload.FileUpload
    * #parseRequest(javax.servlet.http.HttpServletRequest)}), you may
    * either request all contents of file at once using {@link #get()} or
  - * request an {@link java.io.InputStream InputStream} with
  - * {@link #getInputStream()} and process the file without attempting to load
  - * it into memory, which may come handy with large files.
  + * request an {@link java.io.InputStream InputStream} with {@link #getInputStream()}
  + * and process the file without attempting to load it into memory, which
  + * may come handy with large files.
    *
    * <p> While this interface does not extend
    * <code>javax.activation.DataSource</code> per se (to avoid a seldom used
  @@ -94,9 +94,10 @@
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Revision$ $Date$
  + * @version $Id$
    */
  -public interface FileItem {
  +public interface FileItem
  +{
   
   
       // ------------------------------- Methods from javax.activation.DataSource
  
  
  
  1.11      +132 -64   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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FileUpload.java	18 Aug 2002 06:09:21 -0000	1.10
  +++ FileUpload.java	22 Aug 2002 04:26:47 -0000	1.11
  @@ -95,9 +95,10 @@
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Revision$ $Date$
  + * @version $Id$
    */
  -public class FileUpload {
  +public class FileUpload
  +{
   
       // ----------------------------------------------------- Manifest constants
   
  @@ -193,7 +194,8 @@
        *
        * @return The maximum allowed size, in bytes.
        */
  -    public int getSizeMax() {
  +    public int getSizeMax() 
  +    {
           return sizeMax;
       }
   
  @@ -203,7 +205,8 @@
        *
        * @param sizeMax The maximum allowed size, in bytes, or -1 for no maximum.
        */
  -    public void setSizeMax(int sizeMax) {
  +    public void setSizeMax(int sizeMax) 
  +    {
           this.sizeMax = sizeMax;
       }
   
  @@ -214,7 +217,8 @@
        *
        * @return The size threshold, in bytes.
        */
  -    public int getSizeThreshold() {
  +    public int getSizeThreshold()
  +    {
           return sizeThreshold;
       }
   
  @@ -224,7 +228,8 @@
        *
        * @param sizeThreshold The size threshold, in bytes.
        */
  -    public void setSizeThreshold(int sizeThreshold) {
  +    public void setSizeThreshold(int sizeThreshold) 
  +    {
           this.sizeThreshold = sizeThreshold;
       }
   
  @@ -235,7 +240,8 @@
        *
        * @return The path to the temporary file location.
        */
  -    public String getRepositoryPath() {
  +    public String getRepositoryPath()
  +    {
           return repositoryPath;
       }
   
  @@ -245,7 +251,8 @@
        *
        * @param repositoryPath The path to the temporary file location.
        */
  -    public void setRepositoryPath(String repositoryPath) {
  +    public void setRepositoryPath(String repositoryPath) 
  +    {
           this.repositoryPath = repositoryPath;
       }
   
  @@ -256,7 +263,8 @@
        *
        * @return The fully qualified name of the Java class.
        */
  -    public String getFileItemClassName() {
  +    public String getFileItemClassName()
  +    {
           return fileItemClassName;
       }
   
  @@ -267,7 +275,8 @@
        *
        * @param fileItemClassName The fully qualified name of the Java class.
        */
  -    public void setFileItemClassName(String fileItemClassName) {
  +    public void setFileItemClassName(String fileItemClassName)
  +    {
           this.fileItemClassName = fileItemClassName;
           this.newInstanceMethod = null;
       }
  @@ -290,7 +299,8 @@
        *                                the request or storing files.
        */
       public List /* FileItem */ parseRequest(HttpServletRequest req)
  -            throws FileUploadException {
  +        throws FileUploadException
  +    {
           return parseRequest(req, getSizeThreshold(), getSizeMax(), 
                               getRepositoryPath());
       }
  @@ -315,28 +325,32 @@
       public List /* FileItem */ parseRequest(HttpServletRequest req,
                                               int sizeThreshold, 
                                               int sizeMax, String path)
  -            throws FileUploadException {
  -
  +        throws FileUploadException
  +    {
           ArrayList items = new ArrayList();
           String contentType = req.getHeader(CONTENT_TYPE);
   
  -        if (!contentType.startsWith(MULTIPART)) {
  +        if (!contentType.startsWith(MULTIPART))
  +        {
               throw new FileUploadException("the request doesn't contain a " +
                   MULTIPART_FORM_DATA + " or " + MULTIPART_MIXED + " stream");
           }
           int requestSize = req.getContentLength();
   
  -        if (requestSize == -1) {
  +        if (requestSize == -1)
  +        {
               throw new FileUploadException("the request was rejected because " +
                   "it's size is unknown");
           }
   
  -        if (sizeMax >= 0 && requestSize > sizeMax) {
  +        if (sizeMax >= 0 && requestSize > sizeMax)
  +        {
               throw new FileUploadException("the request was rejected because " +
                   "it's size exceeds allowed range");
           }
   
  -        try {
  +        try
  +        {
               byte[] boundary = contentType.substring(
                   contentType.indexOf("boundary=") + 9).getBytes();
   
  @@ -344,13 +358,16 @@
   
               MultipartStream multi = new MultipartStream(input, boundary);
               boolean nextPart = multi.skipPreamble();
  -            while (nextPart) {
  +            while (nextPart)
  +            {
                   Map headers = parseHeaders(multi.readHeaders());
                   String fieldName = getFieldName(headers);
  -                if (fieldName != null) {
  +                if (fieldName != null)
  +                {
                       String subContentType = getHeader(headers, CONTENT_TYPE);
                       if (subContentType != null && subContentType
  -                                                .startsWith(MULTIPART_MIXED)) {
  +                                                .startsWith(MULTIPART_MIXED))
  +                    {
                           // Multiple files.
                           byte[] subBoundary =
                               subContentType.substring(
  @@ -358,22 +375,29 @@
                                   .indexOf("boundary=") + 9).getBytes();
                           multi.setBoundary(subBoundary);
                           boolean nextSubPart = multi.skipPreamble();
  -                        while (nextSubPart) {
  +                        while (nextSubPart)
  +                        {
                               headers = parseHeaders(multi.readHeaders());
  -                            if (getFileName(headers) != null) {
  +                            if (getFileName(headers) != null)
  +                            {
                                   FileItem item = 
                                       createItem(sizeThreshold, path,
                                                  headers, requestSize);
                                   OutputStream os = 
                                       ((DefaultFileItem) item).getOutputStream();
  -                                try {
  +                                try
  +                                {
                                       multi.readBodyData(os);
  -                                } finally {
  +                                }
  +                                finally
  +                                {
                                       os.close();
                                   }
                                   item.setFieldName(getFieldName(headers));
                                   items.add(item);
  -                            } else {
  +                            }
  +                            else
  +                            {
                                   // Ignore anything but files inside
                                   // multipart/mixed.
                                   multi.discardBodyData();
  @@ -381,31 +405,42 @@
                               nextSubPart = multi.readBoundary();
                           }
                           multi.setBoundary(boundary);
  -                    } else {
  -                        if (getFileName(headers) != null) {
  +                    }
  +                    else
  +                    {
  +                        if (getFileName(headers) != null)
  +                        {
                               // A single file.
                               FileItem item = createItem(sizeThreshold, 
                                                          path, headers,
                                                          requestSize);
                               OutputStream os = 
                                   ((DefaultFileItem) item).getOutputStream();
  -                            try {
  +                            try
  +                            {
                                   multi.readBodyData(os);
  -                            } finally {
  +                            }
  +                            finally
  +                            {
                                   os.close();
                               }
                               item.setFieldName(getFieldName(headers));
                               items.add(item);
  -                        } else {
  +                        }
  +                        else
  +                        {
                               // A form field.
                               FileItem item = createItem(sizeThreshold,
                                                          path, headers,
                                                          requestSize);
                               OutputStream os = 
                                   ((DefaultFileItem) item).getOutputStream();
  -                            try {
  +                            try
  +                            {
                                   multi.readBodyData(os);
  -                            } finally {
  +                            }
  +                            finally
  +                            {
                                   os.close();
                               }
                               item.setFieldName(getFieldName(headers));
  @@ -413,13 +448,17 @@
                               items.add(item);
                           }
                       }
  -                } else {
  +                }
  +                else
  +                {
                       // Skip this part.
                       multi.discardBodyData();
                   }
                   nextPart = multi.readBoundary();
               }
  -        } catch (IOException e) {
  +        }
  +        catch (IOException e)
  +        {
               throw new FileUploadException(
                   "Processing of " + MULTIPART_FORM_DATA +
                       " request failed. " + e.getMessage());
  @@ -440,13 +479,16 @@
        *
        * @return The file name for the current <code>encapsulation</code>.
        */
  -    protected String getFileName(Map /* String, String */ headers) {
  +    protected String getFileName(Map /* String, String */ headers)
  +    {
           String fileName = null;
           String cd = getHeader(headers, CONTENT_DISPOSITION);
  -        if (cd.startsWith(FORM_DATA) || cd.startsWith(ATTACHMENT)) {
  +        if (cd.startsWith(FORM_DATA) || cd.startsWith(ATTACHMENT))
  +        {
               int start = cd.indexOf("filename=\"");
               int end = cd.indexOf('"', start + 10);
  -            if (start != -1 && end != -1) {
  +            if (start != -1 && end != -1)
  +            {
                   fileName = cd.substring(start + 10, end).trim();
               }            
           }
  @@ -462,13 +504,16 @@
        *
        * @return The field name for the current <code>encapsulation</code>.
        */
  -    protected String getFieldName(Map /* String, String */ headers) {
  +    protected String getFieldName(Map /* String, String */ headers)
  +    {
           String fieldName = null;
           String cd = getHeader(headers, CONTENT_DISPOSITION);
  -        if (cd != null && cd.startsWith(FORM_DATA)) {
  +        if (cd != null && cd.startsWith(FORM_DATA))
  +        {
               int start = cd.indexOf("name=\"");
               int end = cd.indexOf('"', start + 6);
  -            if (start != -1 && end != -1) {
  +            if (start != -1 && end != -1)
  +            {
                   fieldName = cd.substring(start + 6, end);
               }
           }
  @@ -493,17 +538,20 @@
                                     String path,
                                     Map /* String, String */ headers,
                                     int requestSize)
  -            throws FileUploadException {
  -
  +        throws FileUploadException
  +    {
           Method newInstanceMethod = getNewInstanceMethod();
           Object[] args = new Object[] {
                   path, getFileName(headers), getHeader(headers, CONTENT_TYPE),
                   new Integer(requestSize), new Integer(sizeThreshold) };
           FileItem fileItem = null;
   
  -        try {
  +        try
  +        {
               fileItem = (FileItem) newInstanceMethod.invoke(null, args);
  -        } catch (Exception e) {
  +        }
  +        catch (Exception e)
  +        {
               throw new FileUploadException(e.toString());
           }
   
  @@ -524,10 +572,11 @@
        * @exception FileUploadException if an error occurs.
        */
       protected Method getNewInstanceMethod()
  -            throws FileUploadException {
  -
  +        throws FileUploadException
  +    {
           // If the method is already cached, just return it.
  -        if (this.newInstanceMethod != null) {
  +        if (this.newInstanceMethod != null)
  +        {
               return this.newInstanceMethod;
           }
   
  @@ -536,17 +585,22 @@
                   Thread.currentThread().getContextClassLoader();
           Class fileItemClass = null;
   
  -        if (classLoader == null) {
  +        if (classLoader == null)
  +        {
               classLoader = getClass().getClassLoader();
           }
   
  -        try {
  +        try
  +        {
               fileItemClass = classLoader.loadClass(fileItemClassName);
  -        } catch (Exception e) {
  +        }
  +        catch (Exception e)
  +        {
               throw new FileUploadException(e.toString());
           }
   
  -        if (fileItemClass == null) {
  +        if (fileItemClass == null)
  +        {
               throw new FileUploadException(
                       "Failed to load FileItem class: " + fileItemClassName);
           }
  @@ -558,7 +612,8 @@
           Method newInstanceMethod = MethodUtils.getAccessibleMethod(
                   fileItemClass, "newInstance", parameterTypes);
   
  -        if (newInstanceMethod == null) {
  +        if (newInstanceMethod == null)
  +        {
               throw new FileUploadException(
                       "Failed find newInstance() method in FileItem class: "
                               + fileItemClassName);
  @@ -582,27 +637,34 @@
        *
        * @return A <code>Map</code> containing the parsed HTTP request headers.
        */
  -    protected Map /* String, String */ parseHeaders(String headerPart) {
  +    protected Map /* String, String */ parseHeaders(String headerPart)
  +    {
           Map headers = new HashMap();
           char buffer[] = new char[MAX_HEADER_SIZE];
           boolean done = false;
           int j = 0;
           int i;
           String header, headerName, headerValue;
  -        try {
  -            while (!done) {
  +        try
  +        {
  +            while (!done)
  +            {
                   i = 0;
                   // Copy a single line of characters into the buffer,
                   // omitting trailing CRLF.
  -                while (i < 2 || buffer[i - 2] != '\r'
  -                        || buffer[i - 1] != '\n') {
  +                while (i < 2 || buffer[i - 2] != '\r' || buffer[i - 1] != '\n')
  +                {
                       buffer[i++] = headerPart.charAt(j++);
                   }
                   header = new String(buffer, 0, i - 2);
  -                if (header.equals("")) {
  +                if (header.equals(""))
  +                {
                       done = true;
  -                } else {
  -                    if (header.indexOf(':') == -1) {
  +                }
  +                else
  +                {
  +                    if (header.indexOf(':') == -1)
  +                    {
                           // This header line is malformed, skip it.
                           continue;
                       }
  @@ -610,18 +672,23 @@
                           .trim().toLowerCase();
                       headerValue =
                           header.substring(header.indexOf(':') + 1).trim();
  -                    if (getHeader(headers, headerName) != null) {
  +                    if (getHeader(headers, headerName) != null)
  +                    {
                           // More that one heder of that name exists,
                           // append to the list.
                           headers.put(headerName,
                                       getHeader(headers, headerName) + ',' +
                                       headerValue);
  -                    } else {
  +                    }
  +                    else
  +                    {
                           headers.put(headerName, headerValue);
                       }
                   }
               }
  -        } catch (IndexOutOfBoundsException e) {
  +        }
  +        catch (IndexOutOfBoundsException e)
  +        {
               // Headers were malformed. continue with all that was
               // parsed.
           }
  @@ -640,7 +707,8 @@
        *         there were multiple headers of that name.
        */
       protected final String getHeader(Map /* String, String */ headers,
  -                                     String name) {
  +                                     String name)
  +    {
           return (String) headers.get(name.toLowerCase());
       }
   
  
  
  
  1.5       +8 -4      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FileUploadException.java	18 Aug 2002 06:09:21 -0000	1.4
  +++ FileUploadException.java	22 Aug 2002 04:26:47 -0000	1.5
  @@ -67,14 +67,17 @@
    * Exception for errors encountered processing the request.
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Revision$ $Date$
  + * @version $Id$
    */
  -public class FileUploadException extends Exception {
  +public class FileUploadException
  +    extends Exception
  +{
   
       /**
        * Constructs a new <code>FileUploadException</code> without message.
        */
  -    public FileUploadException() {
  +    public FileUploadException()
  +    {
       }
   
       /**
  @@ -83,7 +86,8 @@
        *
        * @param msg the error message.
        */
  -    public FileUploadException(String msg) {
  +    public FileUploadException(String msg)
  +    {
           super(msg);
       }
   }
  
  
  
  1.7       +145 -64   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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MultipartStream.java	18 Aug 2002 06:09:21 -0000	1.6
  +++ MultipartStream.java	22 Aug 2002 04:26:47 -0000	1.7
  @@ -126,9 +126,10 @@
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Revision$ $Date$
  + * @version $Id$
    */
  -public class MultipartStream {
  +public class MultipartStream
  +{
   
       // ----------------------------------------------------- Manifest constants
   
  @@ -229,7 +230,8 @@
       /**
        * Default constructor.
        */
  -    public MultipartStream() {
  +    public MultipartStream()
  +    {
       }
   
   
  @@ -248,7 +250,8 @@
        */
       public MultipartStream(InputStream input,
                              byte[] boundary,
  -                           int bufSize) {
  +                           int bufSize)
  +    {
           this.input = input;
           this.bufSize = bufSize;
           this.buffer = new byte[bufSize];
  @@ -278,8 +281,10 @@
        *
        * @exception IOException when an error occurs.
        */
  -    public MultipartStream(InputStream input, byte[] boundary)
  -            throws IOException {
  +    public MultipartStream(InputStream input,
  +                           byte[] boundary)
  +        throws IOException
  +    {
           this(input, boundary, DEFAULT_BUFSIZE);
       }
   
  @@ -295,13 +300,17 @@
        *
        * @exception IOException if there is no more data available.
        */
  -    public byte readByte() throws IOException {
  +    public byte readByte()
  +        throws IOException
  +    {
           // Buffer depleted ?
  -        if (head == tail) {
  +        if (head == tail)
  +        {
               head = 0;
               // Refill.
               tail = input.read(buffer, head, bufSize);
  -            if (tail == -1) {
  +            if (tail == -1)
  +            {
                   // No more data available.
                   throw new IOException("No more data is available");
               }
  @@ -320,23 +329,33 @@
        * @exception MalformedStreamException if the stream ends unexpecetedly or
        *                                     fails to follow required syntax.
        */
  -    public boolean readBoundary() throws MalformedStreamException {
  +    public boolean readBoundary()
  +        throws MalformedStreamException
  +    {
           byte[] marker = new byte[2];
           boolean nextChunk = false;
   
           head += boundaryLength;
  -        try {
  +        try
  +        {
               marker[0] = readByte();
               marker[1] = readByte();
  -            if (arrayequals(marker, STREAM_TERMINATOR, 2)) {
  +            if (arrayequals(marker, STREAM_TERMINATOR, 2))
  +            {
                   nextChunk = false;
  -            } else if (arrayequals(marker, FIELD_SEPARATOR, 2)) {
  +            }
  +            else if (arrayequals(marker, FIELD_SEPARATOR, 2))
  +            {
                   nextChunk = true;
  -            } else {
  +            }
  +            else
  +            {
                   throw new MalformedStreamException(
                           "Unexpected characters follow a boundary");
               }
  -        } catch (IOException e) {
  +        }
  +        catch (IOException e)
  +        {
               throw new MalformedStreamException("Stream ended unexpectedly");
           }
           return nextChunk;
  @@ -362,8 +381,11 @@
        *                                     has a different length than the one
        *                                     being currently parsed.
        */
  -    public void setBoundary(byte[] boundary) throws IllegalBoundaryException {
  -        if (boundary.length != boundaryLength - 4) {
  +    public void setBoundary(byte[] boundary)
  +        throws IllegalBoundaryException
  +    {
  +        if (boundary.length != boundaryLength - 4)
  +        {
               throw new IllegalBoundaryException(
                       "The length of a boundary token can not be changed");
           }
  @@ -386,25 +408,35 @@
        *
        * @exception MalformedStreamException if the stream ends unexpecetedly.
        */
  -    public String readHeaders() throws MalformedStreamException {
  +    public String readHeaders()
  +        throws MalformedStreamException
  +    {
           int i = 0;
           byte b[] = new byte[1];
           StringBuffer buf = new StringBuffer();
           int sizeMax = HEADER_PART_SIZE_MAX;
           int size = 0;
  -        while (i < 4) {
  -            try {
  +        while (i < 4)
  +        {
  +            try
  +            {
                   b[0] = readByte();
  -            } catch (IOException e) {
  +            }
  +            catch (IOException e)
  +            {
                   throw new MalformedStreamException("Stream ended unexpectedly");
               }
               size++;
  -            if (b[0] == HEADER_SEPARATOR[i]) {
  +            if (b[0] == HEADER_SEPARATOR[i])
  +            {
                   i++;
  -            } else {
  +            }
  +            else
  +            {
                   i = 0;
               }
  -            if (size <= sizeMax) {
  +            if (size <= sizeMax)
  +            {
                   buf.append(new String(b));
               }
           }
  @@ -429,28 +461,36 @@
        * @exception IOException              if an i/o error occurs.
        */
       public int readBodyData(OutputStream output)
  -            throws MalformedStreamException, IOException {
  -
  +        throws MalformedStreamException,
  +               IOException
  +    {
           boolean done = false;
           int pad;
           int pos;
           int bytesRead;
           int total = 0;
  -        while (!done) {
  +        while (!done)
  +        {
               // Is boundary token present somewere in the buffer?
               pos = findSeparator();
  -            if (pos != -1) {
  +            if (pos != -1)
  +            {
                   // Write the rest of the data before the boundary.
                   output.write(buffer, head, pos - head);
                   total += pos - head;
                   head = pos;
                   done = true;
  -            } else {
  +            }
  +            else
  +            {
                   // Determine how much data should be kept in the
                   // buffer.
  -                if (tail - head > keepRegion) {
  +                if (tail - head > keepRegion)
  +                {
                       pad = keepRegion;
  -                } else {
  +                }
  +                else
  +                {
                       pad = tail - head;
                   }
                   // Write out the data belonging to the body-data.
  @@ -465,9 +505,12 @@
                   bytesRead = input.read(buffer, pad, bufSize - pad);
   
                   // [pprrrrrrr]
  -                if (bytesRead != -1) {
  +                if (bytesRead != -1)
  +                {
                       tail = pad + bytesRead;
  -                } else {
  +                }
  +                else
  +                {
                       // The last pad amount is left in the buffer.
                       // Boundary can't be in there so write out the
                       // data you have and signal an error condition.
  @@ -497,27 +540,35 @@
        * @exception IOException              if an i/o error occurs.
        */
       public int discardBodyData()
  -        throws MalformedStreamException, IOException {
  -
  +        throws MalformedStreamException,
  +               IOException
  +    {
           boolean done = false;
           int pad;
           int pos;
           int bytesRead;
           int total = 0;
  -        while (!done) {
  +        while (!done)
  +        {
               // Is boundary token present somewere in the buffer?
               pos = findSeparator();
  -            if (pos != -1) {
  +            if (pos != -1)
  +            {
                   // Write the rest of the data before the boundary.
                   total += pos - head;
                   head = pos;
                   done = true;
  -            } else {
  +            }
  +            else
  +            {
                   // Determine how much data should be kept in the
                   // buffer.
  -                if (tail - head > keepRegion) {
  +                if (tail - head > keepRegion)
  +                {
                       pad = keepRegion;
  -                } else {
  +                }
  +                else
  +                {
                       pad = tail - head;
                   }
                   total += tail - head - pad;
  @@ -530,9 +581,12 @@
                   bytesRead = input.read(buffer, pad, bufSize - pad);
   
                   // [pprrrrrrr]
  -                if (bytesRead != -1) {
  +                if (bytesRead != -1)
  +                {
                       tail = pad + bytesRead;
  -                } else {
  +                }
  +                else
  +                {
                       // The last pad amount is left in the buffer.
                       // Boundary can't be in there so signal an error
                       // condition.
  @@ -554,20 +608,27 @@
        *
        * @exception IOException if an i/o error occurs.
        */
  -    public boolean skipPreamble() throws IOException {
  +    public boolean skipPreamble()
  +        throws IOException
  +    {
           // First delimiter may be not preceeded with a CRLF.
           System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2);
           boundaryLength = boundary.length - 2;
  -        try {
  +        try
  +        {
               // Discard all data up to the delimiter.
               discardBodyData();
   
               // Read boundary - if succeded, the stream contains an
               // encapsulation.
               return readBoundary();
  -        } catch (MalformedStreamException e) {
  +        }
  +        catch (MalformedStreamException e)
  +        {
               return false;
  -        } finally {
  +        }
  +        finally
  +        {
               // Restore delimiter.
               System.arraycopy(boundary, 0, boundary, 2, boundary.length - 2);
               boundaryLength = boundary.length;
  @@ -590,9 +651,12 @@
        */
       public static boolean arrayequals(byte[] a,
                                         byte[] b,
  -                                      int count) {
  -        for (int i = 0; i < count; i++) {
  -            if (a[i] != b[i]) {
  +                                      int count)
  +    {
  +        for (int i = 0; i < count; i++)
  +        {
  +            if (a[i] != b[i])
  +            {
                   return false;
               }
           }
  @@ -611,9 +675,12 @@
        *         <code>buffer</code>, or <code>-1</code> if not found.
        */
       protected int findByte(byte value,
  -                           int pos) {
  -        for (int i = pos; i < tail; i++) {
  -            if (buffer[i] == value) {
  +                           int pos)
  +    {
  +        for (int i = pos; i < tail; i++)
  +        {
  +            if (buffer[i] == value)
  +            {
                   return i;
               }
           }
  @@ -630,24 +697,30 @@
        *         beginning of the <code>buffer</code>, or <code>-1</code> if
        *         not found.
        */
  -    protected int findSeparator() {
  +    protected int findSeparator()
  +    {
           int first;
           int match = 0;
           int maxpos = tail - boundaryLength;
           for (first = head;
                (first <= maxpos) && (match != boundaryLength);
  -             first++) {
  +             first++)
  +        {
               first = findByte(boundary[0], first);
  -            if (first == -1 || (first > maxpos)) {
  +            if (first == -1 || (first > maxpos))
  +            {
                   return -1;
               }
  -            for (match = 1; match < boundaryLength; match++) {
  -                if (buffer[first + match] != boundary[match]) {
  +            for (match = 1; match < boundaryLength; match++)
  +            {
  +                if (buffer[first + match] != boundary[match])
  +                {
                       break;
                   }
               }
           }
  -        if (match == boundaryLength) {
  +        if (match == boundaryLength)
  +        {
               return first - 1;
           }
           return -1;
  @@ -658,12 +731,15 @@
        * Thrown to indicate that the input stream fails to follow the
        * required syntax.
        */
  -    public class MalformedStreamException extends IOException {
  +    public class MalformedStreamException
  +        extends IOException
  +    {
           /**
            * Constructs a <code>MalformedStreamException</code> with no
            * detail message.
            */
  -        public MalformedStreamException() {
  +        public MalformedStreamException()
  +        {
               super();
           }
   
  @@ -673,7 +749,8 @@
            *
            * @param message The detail message.
            */
  -        public MalformedStreamException(String message) {
  +        public MalformedStreamException(String message)
  +        {
               super(message);
           }
       }
  @@ -682,12 +759,15 @@
       /**
        * Thrown upon attempt of setting an invalid boundary token.
        */
  -    public class IllegalBoundaryException extends IOException {
  +    public class IllegalBoundaryException
  +        extends IOException
  +    {
           /**
            * Constructs an <code>IllegalBoundaryException</code> with no
            * detail message.
            */
  -        public IllegalBoundaryException() {
  +        public IllegalBoundaryException()
  +        {
               super();
           }
   
  @@ -697,7 +777,8 @@
            *
            * @param message The detail message.
            */
  -        public IllegalBoundaryException(String message) {
  +        public IllegalBoundaryException(String message)
  +        {
               super(message);
           }
       }
  
  
  

--
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