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 Sun, 18 Aug 2002 06:09:21 GMT
martinc     2002/08/17 23:09:21

  Modified:    fileupload/src/java/org/apache/commons/fileupload
                        DefaultFileItem.java FileItem.java FileUpload.java
                        FileUploadException.java MultipartStream.java
  Log:
  Stylistic changes only, to adhere to coding conventions and keep
  checkstyle happy.
  
  Revision  Changes    Path
  1.11      +62 -133   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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DefaultFileItem.java	22 Jul 2002 07:21:54 -0000	1.10
  +++ DefaultFileItem.java	18 Aug 2002 06:09:21 -0000	1.11
  @@ -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 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 in 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,11 +95,9 @@
    * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public class DefaultFileItem
  -    implements FileItem
  -{
  +public class DefaultFileItem implements FileItem {
   
       // ----------------------------------------------------------- Data members
   
  @@ -159,8 +157,7 @@
       /**
        * Default constructor.
        */
  -    public DefaultFileItem()
  -    {
  +    public DefaultFileItem() {
       }
   
   
  @@ -174,8 +171,7 @@
        * @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;
       }
  @@ -193,17 +189,11 @@
        *
        * @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;
               }
  @@ -219,8 +209,7 @@
        * @return The content type passed by the browser or <code>null</code> if
        *         not defined.
        */
  -    public String getContentType()
  -    {
  +    public String getContentType() {
           return contentType;
       }
   
  @@ -230,8 +219,7 @@
        *
        * @return The original filename in the client's filesystem.
        */
  -    public String getName()
  -    {
  +    public String getName() {
           return fileName;
       }
   
  @@ -246,8 +234,7 @@
        * @return <code>true</code> if the file contents will be read
        *         from memory.
        */
  -    public boolean isInMemory()
  -    {
  +    public boolean isInMemory() {
           return (content != null || byteStream != null);
       }
   
  @@ -257,18 +244,12 @@
        *
        * @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;
           }
       }
  @@ -281,25 +262,17 @@
        *
        * @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;
               }
  @@ -322,8 +295,7 @@
        *                                         encoding is not available.
        */
       public String getString(String encoding)
  -        throws UnsupportedEncodingException
  -    {
  +            throws UnsupportedEncodingException {
           return new String(get(), encoding);
       }
   
  @@ -335,8 +307,7 @@
        *
        * @return The contents of the file, as a string.
        */
  -    public String getString()
  -    {
  +    public String getString() {
           return new String(get());
       }
   
  @@ -354,8 +325,7 @@
        * @return The data file, or <code>null</code> if the data is stored in
        *         memory.
        */
  -    public File getStoreLocation()
  -    {
  +    public File getStoreLocation() {
           return storeLocation;
       }
   
  @@ -371,70 +341,49 @@
        *
        * @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.
  @@ -452,12 +401,10 @@
        * 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();
           }
       }
  @@ -469,8 +416,7 @@
        *
        * @return The name of the form field.
        */
  -    public String getFieldName()
  -    {
  +    public String getFieldName() {
           return fieldName;
       }
   
  @@ -480,8 +426,7 @@
        *
        * @param fieldName The name of the form field.
        */
  -    public void setFieldName(String fieldName)
  -    {
  +    public void setFieldName(String fieldName) {
           this.fieldName = fieldName;
       }
   
  @@ -493,8 +438,7 @@
        * @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;
       }
   
  @@ -506,8 +450,7 @@
        * @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;
       }
   
  @@ -518,10 +461,8 @@
       /**
        * 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();
           }
       }
  @@ -536,15 +477,10 @@
        *
        * @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);
           }
       }
  @@ -569,20 +505,16 @@
                                          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;
  @@ -598,19 +530,16 @@
        *
        * @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.7       +8 -9      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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FileItem.java	22 Jul 2002 07:21:54 -0000	1.6
  +++ FileItem.java	18 Aug 2002 06:09:21 -0000	1.7
  @@ -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,10 +94,9 @@
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public interface FileItem
  -{
  +public interface FileItem {
   
   
       // ------------------------------- Methods from javax.activation.DataSource
  
  
  
  1.10      +67 -135   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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FileUpload.java	1 Aug 2002 07:15:57 -0000	1.9
  +++ FileUpload.java	18 Aug 2002 06:09:21 -0000	1.10
  @@ -95,10 +95,9 @@
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public class FileUpload
  -{
  +public class FileUpload {
   
       // ----------------------------------------------------- Manifest constants
   
  @@ -194,8 +193,7 @@
        *
        * @return The maximum allowed size, in bytes.
        */
  -    public int getSizeMax() 
  -    {
  +    public int getSizeMax() {
           return sizeMax;
       }
   
  @@ -205,8 +203,7 @@
        *
        * @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;
       }
   
  @@ -217,8 +214,7 @@
        *
        * @return The size threshold, in bytes.
        */
  -    public int getSizeThreshold()
  -    {
  +    public int getSizeThreshold() {
           return sizeThreshold;
       }
   
  @@ -228,8 +224,7 @@
        *
        * @param sizeThreshold The size threshold, in bytes.
        */
  -    public void setSizeThreshold(int sizeThreshold) 
  -    {
  +    public void setSizeThreshold(int sizeThreshold) {
           this.sizeThreshold = sizeThreshold;
       }
   
  @@ -240,8 +235,7 @@
        *
        * @return The path to the temporary file location.
        */
  -    public String getRepositoryPath()
  -    {
  +    public String getRepositoryPath() {
           return repositoryPath;
       }
   
  @@ -251,8 +245,7 @@
        *
        * @param repositoryPath The path to the temporary file location.
        */
  -    public void setRepositoryPath(String repositoryPath) 
  -    {
  +    public void setRepositoryPath(String repositoryPath) {
           this.repositoryPath = repositoryPath;
       }
   
  @@ -263,8 +256,7 @@
        *
        * @return The fully qualified name of the Java class.
        */
  -    public String getFileItemClassName()
  -    {
  +    public String getFileItemClassName() {
           return fileItemClassName;
       }
   
  @@ -275,8 +267,7 @@
        *
        * @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;
       }
  @@ -299,8 +290,7 @@
        *                                the request or storing files.
        */
       public List /* FileItem */ parseRequest(HttpServletRequest req)
  -        throws FileUploadException
  -    {
  +            throws FileUploadException {
           return parseRequest(req, getSizeThreshold(), getSizeMax(), 
                               getRepositoryPath());
       }
  @@ -325,32 +315,28 @@
       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();
   
  @@ -358,16 +344,13 @@
   
               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(
  @@ -375,29 +358,22 @@
                                   .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();
  @@ -405,42 +381,31 @@
                               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));
  @@ -448,17 +413,13 @@
                               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());
  @@ -479,16 +440,13 @@
        *
        * @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();
               }            
           }
  @@ -504,16 +462,13 @@
        *
        * @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);
               }
           }
  @@ -538,20 +493,17 @@
                                     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());
           }
   
  @@ -572,11 +524,10 @@
        * @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;
           }
   
  @@ -585,22 +536,17 @@
                   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);
           }
  @@ -612,8 +558,7 @@
           Method newInstanceMethod = MethodUtils.getAccessibleMethod(
                   fileItemClass, "newInstance", parameterTypes);
   
  -        if (newInstanceMethod == null)
  -        {
  +        if (newInstanceMethod == null) {
               throw new FileUploadException(
                       "Failed find newInstance() method in FileItem class: "
                               + fileItemClassName);
  @@ -637,34 +582,27 @@
        *
        * @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;
                       }
  @@ -672,23 +610,18 @@
                           .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.
           }
  @@ -707,8 +640,7 @@
        *         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.4       +7 -11     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileUploadException.java	17 Jul 2002 01:17:06 -0000	1.3
  +++ FileUploadException.java	18 Aug 2002 06:09:21 -0000	1.4
  @@ -67,17 +67,14 @@
    * Exception for errors encountered processing the request.
    *
    * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public class FileUploadException
  -    extends Exception
  -{
  +public class FileUploadException extends Exception {
   
       /**
        * Constructs a new <code>FileUploadException</code> without message.
        */
  -    public FileUploadException()
  -    {
  +    public FileUploadException() {
       }
   
       /**
  @@ -86,8 +83,7 @@
        *
        * @param msg the error message.
        */
  -    public FileUploadException(String msg)
  -    {
  +    public FileUploadException(String msg) {
           super(msg);
       }
   }
  
  
  
  1.6       +67 -148   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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- MultipartStream.java	22 Jul 2002 07:21:54 -0000	1.5
  +++ MultipartStream.java	18 Aug 2002 06:09:21 -0000	1.6
  @@ -126,10 +126,9 @@
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:martinc@apache.org">Martin Cooper</a>
    *
  - * @version $Id$
  + * @version $Revision$ $Date$
    */
  -public class MultipartStream
  -{
  +public class MultipartStream {
   
       // ----------------------------------------------------- Manifest constants
   
  @@ -230,8 +229,7 @@
       /**
        * Default constructor.
        */
  -    public MultipartStream()
  -    {
  +    public MultipartStream() {
       }
   
   
  @@ -250,8 +248,7 @@
        */
       public MultipartStream(InputStream input,
                              byte[] boundary,
  -                           int bufSize)
  -    {
  +                           int bufSize) {
           this.input = input;
           this.bufSize = bufSize;
           this.buffer = new byte[bufSize];
  @@ -281,10 +278,8 @@
        *
        * @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);
       }
   
  @@ -300,17 +295,13 @@
        *
        * @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");
               }
  @@ -329,33 +320,23 @@
        * @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;
  @@ -381,11 +362,8 @@
        *                                     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");
           }
  @@ -408,35 +386,25 @@
        *
        * @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));
               }
           }
  @@ -461,36 +429,28 @@
        * @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.
  @@ -505,12 +465,9 @@
                   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.
  @@ -540,35 +497,27 @@
        * @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;
  @@ -581,12 +530,9 @@
                   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.
  @@ -608,27 +554,20 @@
        *
        * @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;
  @@ -651,12 +590,9 @@
        */
       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;
               }
           }
  @@ -675,12 +611,9 @@
        *         <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;
               }
           }
  @@ -697,30 +630,24 @@
        *         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;
  @@ -731,15 +658,12 @@
        * 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();
           }
   
  @@ -749,8 +673,7 @@
            *
            * @param message The detail message.
            */
  -        public MalformedStreamException(String message)
  -        {
  +        public MalformedStreamException(String message) {
               super(message);
           }
       }
  @@ -759,15 +682,12 @@
       /**
        * 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();
           }
   
  @@ -777,8 +697,7 @@
            *
            * @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