ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christopher Taylor" <cstay...@nanshu.com>
Subject Bug in the <copy> task, patch to follow
Date Sat, 23 Feb 2002 10:02:46 GMT
Hello,

I tried submitting a bug to the bugzilla bug system, but it appears to be
down at the moment, so I sent email to general and I'm also sending the same
here:

If you use the <copy> task with filtering turned on, and the file is a
different encoding type than the default decoding, the copy task will mangle
the destination file.

For example, I am using a Windows 2000 workstation with JDK 1.4 installed.
I am putting together a Japanese and English website, where the files are
all in UTF-8 format.  The default encoding (as seen with the following code:

import java.io.*;

...
FileReader reader = new FileReader("some file");
System.out.println (reader.getEncoding());
...

will be CP1252 (US-ASCII).  What the copy task needs is an additional
IMPLIED attribute that specifies the encoding for filtering tasks.  The code
in the org.apache.tools.ant.util.FileUtils class would need to be changed so
it could receive an encoding parameter as well.  Lines 220, 221 of
FileUtils.java would need to be replaced with:

FileInputStream fis = new FileInputStream (sourceFile);
FileOutputStream fos = new FileOutputStream (destFile);
InputStreamReader in = new InputStreamReader (fis, encoding);
OutputStreamWriter out = new OutputStreamWriter (fos, encoding);

This would fix the encoding problems with the filtering, as long as all
content encountered during the filtering process was UTF8 encoded (since
ASCII is subsumed by UTF8, this shouldn't be a problem for most people).

-Chris

P.S. The patch contains changes to FileUtils.java and Copy.java in the same
patch file


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message