From f8f5fb01a4adbd7eabedad2c9e06fc5ce6c4525f Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 3 May 2001 12:54:33 +0000 Subject: [PATCH] Make work for multibyte character sets. PR: 1208 Submitted by: AKIMOTO, Hiroki git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269005 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Replace.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Replace.java b/src/main/org/apache/tools/ant/taskdefs/Replace.java index 559e15678..9384981aa 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Replace.java +++ b/src/main/org/apache/tools/ant/taskdefs/Replace.java @@ -285,13 +285,17 @@ public class Replace extends MatchingTask { BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); // read the entire file into a char[] - int fileLength = (int)(src.length()); - char[] tmpBuf = new char[fileLength]; - int numread = 0; + // size of work buffer may be bigger than needed + // when multibyte characters exist in the source file + int fileLengthInBytes = (int)(src.length()); + char[] tmpBuf = new char[fileLengthInBytes]; + int readChar = 0; int totread = 0; - while (numread != -1 && totread < fileLength) { - numread = br.read(tmpBuf,totread,fileLength); - totread += numread; + while (true) { + readChar = br.read(); + if (readChar < 0) { break; } + tmpBuf[totread] = (char)readChar; + totread++; } // create a String so we can use indexOf