• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: System.out making doubles
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: System.out making doubles


  • Subject: Re: System.out making doubles
  • From: "Sako!" <email@hidden>
  • Date: Tue, 16 Nov 2004 12:19:47 +0100

hello dude,
why dont you ask a concrete question.
do you want to convert double into string?
 
btw, this is a java qustion no relation to wo.
 
Sako.
----- Original Message -----
From: Nathan Dumar
To: WebObjects List
Sent: Tuesday, November 16, 2004 4:44 AM
Subject: System.out making doubles

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, (long)(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 email sent to email@hidden
 _______________________________________________
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

  • Follow-Ups:
    • Re: System.out is repeating the output
      • From: Nathan Dumar <email@hidden>
References: 
 >System.out making doubles (From: Nathan Dumar <email@hidden>)

  • Prev by Date: message "Failure to contact xserve2.local-1085"
  • Next by Date: Save bug -- Java Client WO 5.2.3 MacOSX
  • Previous by thread: System.out making doubles
  • Next by thread: Re: System.out is repeating the output
  • Index(es):
    • Date
    • Thread