1 import java.io.*;
2 import javax.swing.*;
3
4 public class LogStream extends OutputStream {
5
6 OutputStream okstream;
7
8 public LogStream(OutputStream okstream) {
9 this.okstream = okstream;
10 }
11
12 static int maxmessage = 400;
13 StringBuffer message = new StringBuffer();
14 boolean done = false;
15
16 void accumulate(String s) {
17 if (done) return;
18 message.append(s);
19 if (message.length() > maxmessage) {
20 done = true;
21 ErrorLog.log("Uncaught exception!\n"+
22 "This means that there was an error that Carto did not expect\n"+
23 "This may or may not be serious\nThe error messsage started:\n"+
24 message+"\n");
25 }
26 }
27
28 public void write(byte[] b) throws IOException {
29 okstream.write(b);
30 accumulate(new String(b));
31 }
32
33 public void write(byte[] b,int off, int len) throws IOException {
34 okstream.write(b,off,len);
35 accumulate(new String(b,off,len));
36 }
37
38 public void write(int b) throws IOException {
39 okstream.write(b);
40 byte[] bar = new byte[1];
41 bar[0]=(byte)b;
42 accumulate(new String(bar));
43 }
44
45 public void flush() throws IOException {
46 okstream.flush();
47 }
48
49 public void close() throws IOException {
50 okstream.close();
51 }
52 }
53