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:[EMAIL PROTECTED]">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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]