diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/FileUtils.java apache-ant-1.6.5/src/main/org/apache/tools/ant/util/FileUtils.java
--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/FileUtils.java 2006-01-11 13:36:06.044324600 -0500
+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/util/FileUtils.java 2006-01-11 13:35:24.204532100 -0500
@@ -67,7 +67,7 @@
private static boolean onNetWare = Os.isFamily("netware");
private static boolean onDos = Os.isFamily("dos");
- private static final int BUF_SIZE = 8192;
+ protected static final int BUF_SIZE = 8192;
// for toURI
private static boolean[] isSpecial = new boolean[256];
@@ -113,6 +113,28 @@
* @return a new instance of FileUtils.
*/
public static FileUtils newFileUtils() {
+ String version = System.getProperty("java.version");
+ StringTokenizer st = new StringTokenizer(version, ".");
+ boolean supportsNio = false;
+ try {
+ if (st.countTokens() > 2) {
+ int major = Integer.parseInt(st.nextToken());
+ int minor = Integer.parseInt(st.nextToken());
+
+ if (major > 1 || (major == 1 && minor >= 4)) {
+ supportsNio = true;
+ try {
+ Class.forName("org.apache.tools.ant.util.NioFileUtils");
+ return new NioFileUtils();
+ } catch (ClassNotFoundException e1) {
+ // class not included
+ // fall back
+ }
+ }
+ }
+ } catch (NumberFormatException e) {
+ // ignore
+ }
return new FileUtils();
}
diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/NioFileUtils.java apache-ant-1.6.5/src/main/org/apache/tools/ant/util/NioFileUtils.java
--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/NioFileUtils.java 2006-01-11 13:36:06.059948300 -0500
+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/util/NioFileUtils.java 2006-01-11 13:17:51.310102700 -0500
@@ -0,0 +1,224 @@
+/*
+ * Created on Jul 12, 2004
+ *
+ * TODO To change the template for this generated file go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+package org.apache.tools.ant.util;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.nio.channels.FileChannel;
+import java.util.Vector;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.filters.util.ChainReaderHelper;
+import org.apache.tools.ant.types.FilterSetCollection;
+
+/**
+ * @author jbleijen
+ *
+ * TODO To change the template for this generated type comment go to Window -
+ * Preferences - Java - Code Style - Code Templates
+ */
+public class NioFileUtils extends FileUtils {
+
+ private static final int TRANSFER_SIZE = 81920;
+
+ /**
+ * Empty constructor.
+ */
+ protected NioFileUtils() {
+ super();
+ }
+
+ /**
+ * Convenience method to copy a file from a source to a
+ * destination specifying if token filtering must be used, if
+ * filter chains must be used, if source files may overwrite
+ * newer destination files and the last modified time of
+ * destFile
file should be made equal
+ * to the last modified time of sourceFile
.
+ *
+ * @param sourceFile the file to copy from.
+ * Must not be null
.
+ * @param destFile the file to copy to.
+ * Must not be null
.
+ * @param filters the collection of filters to apply to this copy.
+ * @param filterChains filterChains to apply during the copy.
+ * @param overwrite Whether or not the destination file should be
+ * overwritten if it already exists.
+ * @param preserveLastModified Whether or not the last modified time of
+ * the resulting file should be set to that
+ * of the source file.
+ * @param inputEncoding the encoding used to read the files.
+ * @param outputEncoding the encoding used to write the files.
+ * @param project the project instance.
+ *
+ *
+ * @throws IOException if the copying fails.
+ *
+ * @since Ant 1.6
+ */
+ public void copyFile(File sourceFile, File destFile,
+ FilterSetCollection filters, Vector filterChains,
+ boolean overwrite, boolean preserveLastModified,
+ String inputEncoding, String outputEncoding,
+ Project project)
+ throws IOException {
+
+ if (overwrite || !destFile.exists()
+ || destFile.lastModified() < sourceFile.lastModified()) {
+
+ if (destFile.exists() && destFile.isFile()) {
+ destFile.delete();
+ }
+ // ensure that parent dir of dest file exists!
+ // not using getParentFile method to stay 1.1 compat
+ File parent = destFile.getParentFile();
+ if (parent != null && !parent.exists()) {
+ parent.mkdirs();
+ }
+ final boolean filterSetsAvailable = (filters != null
+ && filters.hasFilters());
+ final boolean filterChainsAvailable = (filterChains != null
+ && filterChains.size() > 0);
+ if (filterSetsAvailable) {
+ BufferedReader in = null;
+ BufferedWriter out = null;
+ try {
+ if (inputEncoding == null) {
+ in = new BufferedReader(new FileReader(sourceFile));
+ } else {
+ InputStreamReader isr
+ = new InputStreamReader(new FileInputStream(sourceFile),
+ inputEncoding);
+ in = new BufferedReader(isr);
+ }
+ if (outputEncoding == null) {
+ out = new BufferedWriter(new FileWriter(destFile));
+ } else {
+ OutputStreamWriter osw
+ = new OutputStreamWriter(new FileOutputStream(destFile),
+ outputEncoding);
+ out = new BufferedWriter(osw);
+ }
+ if (filterChainsAvailable) {
+ ChainReaderHelper crh = new ChainReaderHelper();
+ crh.setBufferSize(BUF_SIZE);
+ crh.setPrimaryReader(in);
+ crh.setFilterChains(filterChains);
+ crh.setProject(project);
+ Reader rdr = crh.getAssembledReader();
+ in = new BufferedReader(rdr);
+ }
+ LineTokenizer lineTokenizer = new LineTokenizer();
+ lineTokenizer.setIncludeDelims(true);
+ String newline = null;
+ String line = lineTokenizer.getToken(in);
+ while (line != null) {
+ if (line.length() == 0) {
+ // this should not happen, because the lines are
+ // returned with the end of line delimiter
+ out.newLine();
+ } else {
+ newline = filters.replaceTokens(line);
+ out.write(newline);
+ }
+ line = lineTokenizer.getToken(in);
+ }
+ } finally {
+ close(out);
+ close(in);
+ }
+ } else if (filterChainsAvailable
+ || (inputEncoding != null
+ && !inputEncoding.equals(outputEncoding))
+ || (inputEncoding == null && outputEncoding != null)) {
+ BufferedReader in = null;
+ BufferedWriter out = null;
+ try {
+ if (inputEncoding == null) {
+ in = new BufferedReader(new FileReader(sourceFile));
+ } else {
+ in =
+ new BufferedReader(
+ new InputStreamReader(
+ new FileInputStream(sourceFile),
+ inputEncoding));
+ }
+ if (outputEncoding == null) {
+ out = new BufferedWriter(new FileWriter(destFile));
+ } else {
+ out =
+ new BufferedWriter(
+ new OutputStreamWriter(
+ new FileOutputStream(destFile),
+ outputEncoding));
+ }
+ if (filterChainsAvailable) {
+ ChainReaderHelper crh = new ChainReaderHelper();
+ crh.setBufferSize(BUF_SIZE);
+ crh.setPrimaryReader(in);
+ crh.setFilterChains(filterChains);
+ crh.setProject(project);
+ Reader rdr = crh.getAssembledReader();
+ in = new BufferedReader(rdr);
+ }
+ char[] buffer = new char[BUF_SIZE];
+ while (true) {
+ int nRead = in.read(buffer, 0, buffer.length);
+ if (nRead == -1) {
+ break;
+ }
+ out.write(buffer, 0, nRead);
+ }
+ } finally {
+ close(out);
+ close(in);
+ }
+ } else {
+ FileInputStream in = null;
+ FileOutputStream out = null;
+ FileChannel srcChannel = null;
+ FileChannel destChannel = null;
+
+ try {
+ // we can use direct copy with nio
+ 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, TRANSFER_SIZE, destChannel);
+ }
+ } finally {
+ if (srcChannel != null)
+ srcChannel.close();
+ if (destChannel != null)
+ destChannel.close();
+ if (out != null)
+ out.close();
+ if (in != null)
+ in.close();
+ }
+
+ }
+ if (preserveLastModified) {
+ setFileLastModified(destFile, sourceFile.lastModified());
+ }
+ }
+ }
+}