Author: jawi
Date: Fri Nov 8 11:24:44 2013
New Revision: 1539984
URL: http://svn.apache.org/r1539984
Log:
Added convenience method to copy a file.
Modified:
ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/FileUtils.java
Modified:
ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/FileUtils.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/FileUtils.java?rev=1539984&r1=1539983&r2=1539984&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/FileUtils.java
(original)
+++ ace/trunk/org.apache.ace.test/src/org/apache/ace/test/utils/FileUtils.java
Fri Nov 8 11:24:44 2013
@@ -19,15 +19,19 @@
package org.apache.ace.test.utils;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.nio.channels.FileChannel;
public class FileUtils {
/**
- * Convenience method for creating temp files.
- * It creates a temp file, and then deletes it. This is done so the same
(unique) filename can be used to create a directory.
- *
+ * Convenience method for creating temp files. It creates a temp file, and
then deletes it. This is done so the same
+ * (unique) filename can be used to create a directory.
+ *
* If you use null as the baseDirectoryName, a tempfile is created in the
platform specific temp directory.
+ *
* @throws IOException
*/
public static File createTempFile(File baseDirectory) throws IOException {
@@ -40,16 +44,39 @@ public class FileUtils {
return tempFile;
}
+ public static void copy(File input, File output) throws IOException {
+ FileInputStream fis = new FileInputStream(input);
+ FileOutputStream fos = new FileOutputStream(output);
+
+ try {
+ FileChannel ic = fis.getChannel();
+ FileChannel oc = fos.getChannel();
+ try {
+ oc.transferFrom(ic, 0, ic.size());
+ }
+ finally {
+ oc.close();
+ ic.close();
+ }
+ }
+ finally {
+ fis.close();
+ fos.close();
+ }
+ }
+
/**
* Remove the given directory and all it's files and subdirectories
- * @param directory the name of the directory to remove
+ *
+ * @param directory
+ * the name of the directory to remove
*/
public static void removeDirectoryWithContent(File directory) {
if ((directory == null) || !directory.exists()) {
return;
}
File[] filesAndSubDirs = directory.listFiles();
- for (int i=0; i < filesAndSubDirs.length; i++) {
+ for (int i = 0; i < filesAndSubDirs.length; i++) {
File file = filesAndSubDirs[i];
if (file.isDirectory()) {
removeDirectoryWithContent(file);