Hi,
I appear to have a simple problem which doesn’t work
for some unknown reason. I’ve included my method where I’m
having problems. For some reason the commented line does not work.
Neither does the line above. The length of the string is returned correctly,
but if I output the contents of the string, it still includes the part I’m
trying to remove. Does anyone have any ideas? I’m using
NetBeans 6.5 with Java 1.6_13
public
String[] getText(boolean wait) {
if (this.isConnected()) {
if (wait) {
waitForReady();
telnetOption.clear();
System.out.println("reset TelnetOptions");
}
try {
InputStream in = getInputStream();
byte[] buff = new byte[in.available()];
int read = in.read(buff, 0, buff.length);
if (read > 0) {
String s = new String(buff, 0, buff.length);
if (loginStatus == LoginStatus.LoggedOut) {
String t = s.replaceFirst("[\\r\\n\\s]*", "");
if (t.length() > 0) {
t = t.substring(0, t.indexOf("\r"));
if (t.matches("telnet\\s*\\(.*\\)")) {
messageAYT = "\r\n" + t.replaceFirst(".*\\(",
"").replaceFirst("\\).*", "") + "
here\r\n";
}
}
}
if (wait) {
if (s.endsWith(messageAYT)) {
s = new String(buff, 0, s.length() - messageAYT.length());
//
s = s.substring(0, s.length() - messageAYT.length());
if (s.length() > 800) {
System.err.println("AYT: " + messageAYT.length());
System.err.println("s: " + s.length());
System.err.println("buff: " + buff.length);
System.err.println(s.substring(900));
System.err.println("s: " + s.length());
}
}
}
buffer.append(s);
int len = buffer.length();
if (len > maxBuffer) {
buffer.delete(0, len - maxBuffer);
}
String[] lines = s.split("(\\r\\r\\n|\\r\\n|\\r)");
System.out.println();
for (int i = 0; i < lines.length; i++) {
System.out.println(lines[i]);
}
return lines;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
return null;
}
Regards,
Dale Harris