diff --git a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/FileUtils.java b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/FileUtils.java index e72540108..6d4916d37 100644 --- a/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/FileUtils.java +++ b/proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/util/FileUtils.java @@ -64,6 +64,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.io.Reader; import java.lang.reflect.Method; @@ -157,6 +159,25 @@ public class FileUtils { overwrite, preserveLastModified); } + /** + * Convienence method to copy a file from a source to a + * destination specifying if token filtering 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. + * + * @throws IOException + * + * @since 1.14, Ant 1.5 + */ + public void copyFile(String sourceFile, String destFile, + FilterSetCollection filters, boolean overwrite, + boolean preserveLastModified, String encoding) + throws IOException { + copyFile(new File(sourceFile), new File(destFile), filters, + overwrite, preserveLastModified, encoding); + } + /** * Convienence method to copy a file from a source to a destination. * No filtering is performed. @@ -202,6 +223,26 @@ public class FileUtils { public void copyFile(File sourceFile, File destFile, FilterSetCollection filters, boolean overwrite, boolean preserveLastModified) throws IOException { + copyFile(sourceFile, destFile, filters, overwrite, + preserveLastModified, null); + } + + /** + * Convienence method to copy a file from a source to a + * destination specifying if token filtering must be used, if + * source files may overwrite newer destination files, the last + * modified time of destFile file should be made + * equal to the last modified time of sourceFile and + * which character encoding to assume. + * + * @throws IOException + * + * @since 1.14, Ant 1.5 + */ + public void copyFile(File sourceFile, File destFile, + FilterSetCollection filters, boolean overwrite, + boolean preserveLastModified, String encoding) + throws IOException { if (overwrite || !destFile.exists() || destFile.lastModified() < sourceFile.lastModified()) { @@ -218,8 +259,16 @@ public class FileUtils { } if (filters != null && filters.hasFilters()) { - BufferedReader in = new BufferedReader(new FileReader(sourceFile)); - BufferedWriter out = new BufferedWriter(new FileWriter(destFile)); + BufferedReader in = null; + BufferedWriter out = null; + + if (encoding == null) { + in = new BufferedReader(new FileReader(sourceFile)); + out = new BufferedWriter(new FileWriter(destFile)); + } else { + in = new BufferedReader(new InputStreamReader(new FileInputStream(sourceFile), encoding)); + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destFile), encoding)); + } int length; String newline = null;