Browse Source

More code reuse

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274510 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
f1122490cd
2 changed files with 6 additions and 17 deletions
  1. +3
    -17
      src/main/org/apache/tools/ant/taskdefs/Replace.java
  2. +3
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java

+ 3
- 17
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -402,25 +402,11 @@ public class Replace extends MatchingTask {
BufferedReader br = new BufferedReader(reader);
BufferedWriter bw = new BufferedWriter(writer);

// read the entire file into a StringBuffer
// size of work buffer may be bigger than needed
// when multibyte characters exist in the source file
// but then again, it might be smaller than needed on
// platforms like Windows where length can't be trusted
int fileLengthInBytes = (int) src.length();
StringBuffer tmpBuf = new StringBuffer(fileLengthInBytes);
int readChar = 0;
int totread = 0;
while (true) {
readChar = br.read();
if (readChar < 0) { break; }
tmpBuf.append((char) readChar);
totread++;
String buf = fileUtils.readFully(br);
if (buf == null) {
buf = "";
}

// create a String so we can use indexOf
String buf = tmpBuf.toString();

//Preserve original string (buf) so we can compare the result
String newString = new String(buf);



+ 3
- 0
src/main/org/apache/tools/ant/taskdefs/optional/ReplaceRegExp.java View File

@@ -417,6 +417,9 @@ public class ReplaceRegExp extends Task {
pw.flush();
} else {
String buf = fileUtils.readFully(br);
if (buf == null) {
buf = "";
}

String res = doReplace(regex, subs, buf, options);



Loading…
Cancel
Save