ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sam Ruby" <ru...@us.ibm.com>
Subject Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Replace.java
Date Thu, 20 Sep 2001 02:15:51 GMT
For reasons I don't understand, the following commit is causing the Expand
task (aka unzip) to produce files of zero length.  This ultimately produces
the errors that you can see at
http://nagoya.apache.org/~rubys/gump/rhino.html .

I've reproduced on Solaris, Linux, and Win2K.

- Sam Ruby

conor       01/09/19 05:10:25

  Modified:    docs/manual/CoreTasks replace.html
               src/main/org/apache/tools/ant/taskdefs Replace.java
  Log:
  Add encoding to <replace> task so that replace can work on double byte
  characters

  Revision  Changes    Path
  1.4       +5 -0      jakarta-ant/docs/manual/CoreTasks/replace.html

  Index: replace.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/replace.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- replace.html  2001/07/30 13:35:23  1.3
  +++ replace.html  2001/09/19 12:10:25  1.4
  @@ -31,6 +31,11 @@
         multiple files.</td>
     </tr>
     <tr>
  +    <td valign="top">encoding</td>
  +    <td valign="top">The encoding of the files upon which replace
operates.</td>
  +    <td align="center">No - defaults to default JVM encoding</td>
  +  </tr>
  +  <tr>
       <td valign="top">token</td>
       <td valign="top">the token which must be replaced.</td>
       <td valign="top" align="center">Yes, unless a nested
<code>replacetoken</code>



  1.16      +21 -4
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java

  Index: Replace.java
  ===================================================================
  RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Replace.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -w -u -r1.15 -r1.16
  --- Replace.java  2001/07/30 13:35:23  1.15
  +++ Replace.java  2001/09/19 12:10:25  1.16
  @@ -83,6 +83,9 @@
       private int replaceCount;
       private boolean summary = false;

  +    /** The encoding used to read and write files - if null, uses
default */
  +    private String encoding = null;
  +
       //Inner class
       public class NestedString {

  @@ -291,8 +294,13 @@
           }

           try {
  -            BufferedReader br = new BufferedReader(new FileReader(src));
  -            BufferedWriter bw = new BufferedWriter(new
FileWriter(temp));
  +            Reader fileReader = encoding == null ? new FileReader(src)
  +                                                 : new
InputStreamReader(new FileInputStream(src), encoding);
  +            Writer fileWriter = encoding == null ? new FileWriter(src)
  +                                                 : new
OutputStreamWriter(new FileOutputStream(src), encoding);
  +
  +            BufferedReader br = new BufferedReader(fileReader);
  +            BufferedWriter bw = new BufferedWriter(fileWriter);

               // read the entire file into a StringBuffer
               //   size of work buffer may be bigger than needed
  @@ -354,8 +362,8 @@
                   temp.delete();
               }
           } catch (IOException ioe) {
  -            ioe.printStackTrace();
  -            throw new BuildException(ioe, location);
  +            throw new BuildException("IOException in " + src + " - " +
  +                                     ioe.getClass().getName() + ":" +
ioe.getMessage(), ioe, location);
           }
       }

  @@ -412,6 +420,15 @@
           createReplaceValue().addText(value);
       }

  +    /**
  +     * Set the file encoding to use on the files read and written by
replace
  +     *
  +     * @param encoding the encoding to use on the files
  +     */
  +    public void setEncoding(String encoding) {
  +        this.encoding = encoding;
  +    }
  +
       /**
        * Nested <replacetoken> element.
        */






Mime
View raw message