portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject cvs commit: jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util DirectoryHelper.java
Date Wed, 02 Mar 2005 13:48:34 GMT
ate         2005/03/02 05:48:34

  Modified:    commons/src/java/org/apache/jetspeed/util Tag:
                        deployment-refactoring DirectoryHelper.java
  Log:
  Ensure FileChannels are always closed.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.4.2.1   +34 -5     jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java
  
  Index: DirectoryHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/DirectoryHelper.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- DirectoryHelper.java	31 Jul 2004 20:05:28 -0000	1.4
  +++ DirectoryHelper.java	2 Mar 2005 13:48:34 -0000	1.4.2.1
  @@ -18,14 +18,13 @@
   import java.io.File;
   import java.io.FileFilter;
   import java.io.FileInputStream;
  -import java.io.FileNotFoundException;
   import java.io.FileOutputStream;
   import java.io.IOException;
   import java.nio.channels.FileChannel;
   
   /**
    * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
  - *
  + * @version $Id$
    */
   public class DirectoryHelper
       extends
  @@ -108,7 +107,11 @@
        */
       protected void copyFiles(File srcDir, File dstDir, FileFilter fileFilter) throws IOException
       {
  -             
  +        FileChannel srcChannel = null;
  +        FileChannel dstChannel = null;
  +
  +        try
  +        {
           File[] children = srcDir.listFiles(fileFilter);
           for(int i=0; i<children.length; i++)
           {
  @@ -117,8 +120,8 @@
               {
                   File toFile = new File(dstDir, child.getName());
                   toFile.createNewFile();
  -                FileChannel srcChannel = new FileInputStream(child).getChannel();
  -                FileChannel dstChannel = new FileOutputStream(toFile).getChannel();
  +                srcChannel = new FileInputStream(child).getChannel();
  +                dstChannel = new FileOutputStream(toFile).getChannel();
                   dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
                   srcChannel.close();
                   dstChannel.close();
  @@ -130,6 +133,32 @@
                   copyFiles(child, newSubDir, fileFilter);
               }
           }
  +        }
  +        finally
  +        {
  +            if ( srcChannel != null && srcChannel.isOpen() )
  +            {
  +                try
  +                {
  +                    srcChannel.close();
  +                }
  +                catch (Exception e)
  +                {
  +                    
  +                }
  +            }
  +            if ( dstChannel != null && dstChannel.isOpen() )
  +            {
  +                try
  +                {
  +                    dstChannel.close();
  +                }
  +                catch (Exception e)
  +                {
  +                    
  +                }
  +            }
  +        }
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message