Browse Source

Use NIO when copying files without filtering. PR 30094. Submitted by J Bleijenbergh and Robin Verduijn

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@807523 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
9ae5d99ebe
4 changed files with 63 additions and 7 deletions
  1. +2
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +8
    -0
      contributors.xml
  4. +49
    -7
      src/main/org/apache/tools/ant/util/ResourceUtils.java

+ 2
- 0
CONTRIBUTORS View File

@@ -123,6 +123,7 @@ Ingenonsya France
Ingmar Stein
Irene Rusman
Ivan Ivanov
J Bleijenbergh
Jack J. Woehr
James Duncan Davidson
Jan Cumps
@@ -261,6 +262,7 @@ Robert Streich
Robert Watkins
Roberto Scaramuzzi
Robin Green
Robin Verduijn
Rob Oxspring
Rob van Oostrum
Rodrigo Schmidt


+ 4
- 0
WHATSNEW View File

@@ -905,6 +905,10 @@ Other changes:
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
=============================================



+ 8
- 0
contributors.xml View File

@@ -518,6 +518,10 @@
<first>Ivan</first>
<last>Ivanov</last>
</name>
<name>
<first>J</first>
<last>Bleijenbergh</last>
</name>
<name>
<first>Jack</first>
<middle>J.</middle>
@@ -1066,6 +1070,10 @@
<first>Robin</first>
<last>Green</last>
</name>
<name>
<first>Robin</first>
<last>Verduijn</last>
</name>
<name>
<first>Rob</first>
<last>Oxspring</last>


+ 49
- 7
src/main/org/apache/tools/ant/util/ResourceUtils.java View File

@@ -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 @@ public class ResourceUtils {
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;


Loading…
Cancel
Save