System.out making doubles
System.out making doubles
- Subject: System.out making doubles
- From: Nathan Dumar <email@hidden>
- Date: Mon, 15 Nov 2004 22:44:21 -0500
Hello all.
Something strange is going on, and I can't figure it out. It's probably my code, but I can't find the mistake.
I'm trying to change System.out to a String, which I will then email to myself. For some reason, though, everything is coming out double.
First, I overrode ByteArrayOutputStream's two write methods to do my custom logic, like this (collect all the writes, send message when it has more than 1000 characters or has been 30 seconds since last write):
public class BAOS2 extends ByteArrayOutputStream {
protected StringBuffer body = new StringBuffer();
protected Timer errorTimer = new Timer();
public void write(int b) {
super.write(b);
body.append("write 1\r");
startErrorTimer();
}
public void write(byte[] b, int off, int len) {
super.write(b, off, len);
body.append("write 2\r");
startErrorTimer();
}
public void startErrorTimer() {
body.append("(re-)starting Error Timer\r");
errorTimer.cancel();
errorTimer = new Timer(); // starts or clears? timer
body.append(toString());
if (body.length() > 1000) {
body.append("L = " + body.length() + " > 1000");
STMailer.sendSTMessageRR("email@hidden", "email@hidden", "!!ERROR!!", body.toString());
body = new StringBuffer();
reset();
}
else {
TimerTask sendError = new sendErrorMessageTT();
errorTimer.schedule(sendError, (1000 * 30) );
}
return;
}
public class sendErrorMessageTT extends TimerTask {
public void run() {
body.append("Sent by timer");
STMailer.sendSTMessageRR("email@hidden", "email@hidden", "!!ERROR!!", body.toString());
body = new StringBuffer();
reset();
}
}
}
Then, in Application.java, I set the new outputs:
baos = new BAOS2(); // byte array output stream
PrintStream ps = new PrintStream(baos);
System.setOut(ps);
System.setErr(ps);
To test it all, I do this line *once*:
System.out.println("This is a test.");
... and I get:
write 2
(re-)starting Error Timer
This is a test.write 2
(re-)starting Error Timer
This is a test.
Sent by timer
Notice the repetition. Why?
Thanks for any help!
Nathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden