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

cvs commit: jakarta-turbine-2/src/java/org/apache/turbine/util/upload FileItem.java

jmcnally    02/04/13 10:08:20

  Modified:    src/java/org/apache/turbine/util/upload FileItem.java
  Log:
  backport of patch to the common-fileupload version of FileItem
  
  Revision  Changes    Path
  1.4       +37 -4     jakarta-turbine-2/src/java/org/apache/turbine/util/upload/FileItem.java
  
  Index: FileItem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-2/src/java/org/apache/turbine/util/upload/FileItem.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileItem.java	23 Aug 2001 19:46:37 -0000	1.3
  +++ FileItem.java	13 Apr 2002 17:08:20 -0000	1.4
  @@ -54,6 +54,8 @@
    * <http://www.apache.org/>.
    */
   
  +import java.io.BufferedInputStream;
  +import java.io.BufferedOutputStream;
   import java.io.ByteArrayInputStream;
   import java.io.ByteArrayOutputStream;
   import java.io.File;
  @@ -93,7 +95,7 @@
    * @author <a href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski</a>
    * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  - * @version $Id: FileItem.java,v 1.3 2001/08/23 19:46:37 dlr Exp $
  + * @version $Id: FileItem.java,v 1.4 2002/04/13 17:08:20 jmcnally Exp $
    */
   public class FileItem implements DataSource
   {
  @@ -430,9 +432,40 @@
                */
               if (storeLocation.renameTo(new File(file)) == false)
               {
  -                throw new Exception(
  -                    "Cannot write uploaded file to disk!");
  -            }                
  +                BufferedInputStream in = null;
  +                BufferedOutputStream out = null;
  +                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 )
  +                    {
  +                        out.write(bytes,0,s);
  +                    }
  +                }
  +                finally
  +                {
  +                    try
  +                    {
  +                        in.close();
  +                    }
  +                    catch (Exception e)
  +                    {
  +                                // ignore
  +                    }
  +                    try
  +                    {
  +                        out.close();
  +                    }
  +                    catch (Exception e)
  +                    {
  +                                // ignore
  +                    }
  +                }
  +            }
           }
           else
           {
  
  
  

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