Author: niallp
Date: Fri May 30 04:34:02 2008
New Revision: 661658
URL: http://svn.apache.org/viewvc?rev=661658&view=rev
Log:
IO-157 FileUtils - Return target File from copyFileToDirectory() - thanks to
Kenny MacLeod
Modified:
commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=661658&r1=661657&r2=661658&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
(original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Fri
May 30 04:34:02 2008
@@ -549,14 +549,15 @@
*
* @param srcFile an existing file to copy, must not be <code>null</code>
* @param destDir the directory to place the copy in, must not be
<code>null</code>
+ * @return the new file
*
* @throws NullPointerException if source or destination is null
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs during copying
* @see #copyFile(File, File, boolean)
*/
- public static void copyFileToDirectory(File srcFile, File destDir) throws
IOException {
- copyFileToDirectory(srcFile, destDir, true);
+ public static File copyFileToDirectory(File srcFile, File destDir) throws
IOException {
+ return copyFileToDirectory(srcFile, destDir, true);
}
/**
@@ -571,6 +572,7 @@
* @param destDir the directory to place the copy in, must not be
<code>null</code>
* @param preserveFileDate true if the file date of the copy
* should be the same as the original
+ * @return the new file
*
* @throws NullPointerException if source or destination is
<code>null</code>
* @throws IOException if source or destination is invalid
@@ -578,14 +580,16 @@
* @see #copyFile(File, File, boolean)
* @since Commons IO 1.3
*/
- public static void copyFileToDirectory(File srcFile, File destDir, boolean
preserveFileDate) throws IOException {
+ public static File copyFileToDirectory(File srcFile, File destDir, boolean
preserveFileDate) throws IOException {
if (destDir == null) {
throw new NullPointerException("Destination must not be null");
}
if (destDir.exists() && destDir.isDirectory() == false) {
throw new IllegalArgumentException("Destination '" + destDir + "'
is not a directory");
}
- copyFile(srcFile, new File(destDir, srcFile.getName()),
preserveFileDate);
+ File destFile = new File(destDir, srcFile.getName());
+ copyFile(srcFile, destFile, preserveFileDate);
+ return destFile;
}
/**
Modified:
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java?rev=661658&r1=661657&r2=661658&view=diff
==============================================================================
---
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
(original)
+++
commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
Fri May 30 04:34:02 2008
@@ -883,7 +883,8 @@
//This is to slow things down so we can catch if
//the lastModified date is not ok
- FileUtils.copyFileToDirectory(testFile1, directory);
+ File result = FileUtils.copyFileToDirectory(testFile1, directory);
+ assertEquals("Check File", destination, result);
assertTrue("Check Exist", destination.exists());
assertTrue("Check Full copy", destination.length() == testFile1Size);
/* disabled: Thread.sleep doesn't work reliantly for this case