Browse Source

avoid excessive StringBuffer.toString calls while waiting for a response string. PR 34464. Based on patch by Adam Blinkinsop.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@677887 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
730b669519
4 changed files with 15 additions and 4 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      contributors.xml
  3. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java
  4. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java

+ 1
- 0
CONTRIBUTORS View File

@@ -1,5 +1,6 @@
Amongst other, the following people contributed to ant:

Adam Blinkinsop
Aleksandr Ishutin
Alexey Panchenko
Alexey Solofnenko


+ 4
- 0
contributors.xml View File

@@ -30,6 +30,10 @@
<introduction>
These are some of the many people who have helped Ant become so successful.
</introduction>
<name>
<first>Adam</first>
<last>Blinkinsop</last>
</name>
<name>
<first>Aleksandr</first>
<last>Ishutin</last>


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/net/RExecTask.java View File

@@ -203,14 +203,17 @@ public class RExecTask extends Task {
InputStream is = this.getInputStream();
try {
StringBuffer sb = new StringBuffer();
int windowStart = -s.length();
if (timeout == null || timeout.intValue() == 0) {
while (sb.toString().indexOf(s) == -1) {
while (windowStart++ < 0
|| !sb.substring(windowStart).equals(s)) {
sb.append((char) is.read());
}
} else {
Calendar endTime = Calendar.getInstance();
endTime.add(Calendar.SECOND, timeout.intValue());
while (sb.toString().indexOf(s) == -1) {
while (windowStart++ < 0
|| !sb.substring(windowStart).equals(s)) {
while (Calendar.getInstance().before(endTime)
&& is.available() == 0) {
Thread.sleep(PAUSE_TIME);


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/net/TelnetTask.java View File

@@ -340,14 +340,17 @@ public class TelnetTask extends Task {
InputStream is = this.getInputStream();
try {
StringBuffer sb = new StringBuffer();
int windowStart = -s.length();
if (timeout == null || timeout.intValue() == 0) {
while (sb.toString().indexOf(s) == -1) {
while (windowStart++ < 0
|| !sb.substring(windowStart).equals(s)) {
sb.append((char) is.read());
}
} else {
Calendar endTime = Calendar.getInstance();
endTime.add(Calendar.SECOND, timeout.intValue());
while (sb.toString().indexOf(s) == -1) {
while (windowStart++ < 0
|| !sb.substring(windowStart).equals(s)) {
while (Calendar.getInstance().before(endTime)
&& is.available() == 0) {
Thread.sleep(WAIT_INTERVAL);


Loading…
Cancel
Save