Author: bodewig
Date: Tue Aug 25 08:50:37 2009
New Revision: 807523
URL: http://svn.apache.org/viewvc?rev=807523&view=rev
Log:
Use NIO when copying files without filtering. PR 30094. Submitted by J
Bleijenbergh and Robin Verduijn
Modified:
ant/core/trunk/CONTRIBUTORS
ant/core/trunk/WHATSNEW
ant/core/trunk/contributors.xml
ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
Modified: ant/core/trunk/CONTRIBUTORS
URL:
http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=807523&r1=807522&r2=807523&view=diff
==============================================================================
Binary files - no diff available.
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=807523&r1=807522&r2=807523&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Tue Aug 25 08:50:37 2009
@@ -905,6 +905,10 @@
a property to the number of rows affected by a task execution.
Bugzilla Report 40923.
+ * when Ant copies files without filtering, it will now use NIO
+ channels.
+ Bugzilla Report 30094.
+
Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================
Modified: ant/core/trunk/contributors.xml
URL:
http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=807523&r1=807522&r2=807523&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Tue Aug 25 08:50:37 2009
@@ -519,6 +519,10 @@
<last>Ivanov</last>
</name>
<name>
+ <first>J</first>
+ <last>Bleijenbergh</last>
+ </name>
+ <name>
<first>Jack</first>
<middle>J.</middle>
<last>Woehr</last>
@@ -1067,6 +1071,10 @@
<last>Green</last>
</name>
<name>
+ <first>Robin</first>
+ <last>Verduijn</last>
+ </name>
+ <name>
<first>Rob</first>
<last>Oxspring</last>
</name>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java?rev=807523&r1=807522&r2=807523&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java Tue
Aug 25 08:50:37 2009
@@ -17,19 +17,22 @@
*/
package org.apache.tools.ant.util;
-import java.io.File;
-import java.io.Reader;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
-import java.io.BufferedInputStream;
+import java.io.Reader;
+import java.nio.channels.FileChannel;
import java.util.Arrays;
-import java.util.Vector;
import java.util.Iterator;
+import java.util.Vector;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
@@ -433,6 +436,45 @@
FileUtils.close(out);
FileUtils.close(in);
}
+ } else if (source.as(FileProvider.class) != null
+ && dest.as(FileProvider.class) != null) {
+ File sourceFile =
+ ((FileProvider) source.as(FileProvider.class)).getFile();
+ File destFile =
+ ((FileProvider) dest.as(FileProvider.class)).getFile();
+
+ File parent = destFile.getParentFile();
+ if (parent != null && !parent.isDirectory()
+ && !destFile.getParentFile().mkdirs()) {
+ throw new IOException("failed to create the parent directory"
+ + " for " + destFile);
+ }
+
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ FileChannel srcChannel = null;
+ FileChannel destChannel = null;
+
+ try {
+ in = new FileInputStream(sourceFile);
+ out = new FileOutputStream(destFile);
+
+ srcChannel = in.getChannel();
+ destChannel = out.getChannel();
+
+ long position = 0;
+ long count = srcChannel.size();
+ while (position < count) {
+ position +=
+ srcChannel.transferTo(position, FileUtils.BUF_SIZE,
+ destChannel);
+ }
+ } finally {
+ FileUtils.close(srcChannel);
+ FileUtils.close(destChannel);
+ FileUtils.close(out);
+ FileUtils.close(in);
+ }
} else {
InputStream in = null;
OutputStream out = null;