Subversion Repositories HomeAutomation

Rev

Rev 15 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 15 Rev 73
1
/*
1
/*
2
 * File created by Jimmy
2
 * File created by Jimmy
3
 * at 2004-mar-08 00:24:24
3
 * at 2004-mar-08 00:24:24
4
 */
4
 */
5
package Macbeth.Utilities;
5
package Macbeth.Utilities;
6
 
6
 
7
import java.io.PrintStream;
7
import java.io.PrintStream;
8
import java.io.PipedOutputStream;
8
import java.io.PipedOutputStream;
9
import java.io.PrintWriter;
9
import java.io.PrintWriter;
10
 
10
 
11
/**
11
/**
12
 * Prefixs everything that is written to the stream with a timestamp.
12
 * Prefixs everything that is written to the stream with a timestamp.
13
 * @author Jimmy
13
 * @author Jimmy
14
 */
14
 */
15
public class TimeStampedStream extends PrintStream {
15
public class TimeStampedStream extends PrintStream {
16
    //the underlying stream
16
    //the underlying stream
17
    private PrintStream stream;
17
    private PrintStream stream;
18
 
18
 
19
    /**
19
    /**
20
     * Creates a new instance of TextFormatterStream.
20
     * Creates a new instance of TextFormatterStream.
21
     * @param stream The underlying stream to which the
21
     * @param stream The underlying stream to which the
22
     *               formatted text should be written.
22
     *               formatted text should be written.
23
     */
23
     */
24
    public TimeStampedStream(PrintStream stream) {
24
    public TimeStampedStream(PrintStream stream) {
25
        //construct PrintWriter with non-used PipedOutputStream
25
        //construct PrintWriter with non-used PipedOutputStream
26
        super(new PipedOutputStream());
26
        super(new PipedOutputStream());
27
        //save reference to underlying stream
27
        //save reference to underlying stream
28
        this.stream = stream;
28
        this.stream = stream;
29
    }
29
    }
30
 
30
 
31
    private String timeStamp() {
31
    private String timeStamp() {
32
        return MyDateTime.now("[yyyy-MM-dd HH:mm:ss] ");
32
        return MyDateTime.now("[yyyy-MM-dd HH:mm:ss] ");
33
    }
33
    }
34
 
34
 
35
    /* Override all standard print-methods: */
35
    /* Override all standard print-methods: */
36
 
36
 
37
    public void println(char c[]) {
37
    public void println(char c[]) {
38
        String str = timeStamp() + new String(c, 0, c.length) + MySystem.lineBreak;
38
        String str = timeStamp() + new String(c, 0, c.length) + MySystem.lineBreak;
39
        if (c != null) {
39
        if (c != null) {
40
            stream.print(str);
40
            stream.print(str);
41
        }
41
        }
42
    }
42
    }
43
 
43
 
44
    public void print(char c[]) {
44
    public void print(char c[]) {
45
        String str = timeStamp() + new String(c, 0, c.length);
45
        String str = timeStamp() + new String(c, 0, c.length);
46
        if (c != null) {
46
        if (c != null) {
47
            stream.print(str);
47
            stream.print(str);
48
        }
48
        }
49
    }
49
    }
50
 
50
 
51
    public void println(double d) {
51
    public void println(double d) {
52
        String str = timeStamp() + d + MySystem.lineBreak;
52
        String str = timeStamp() + d + MySystem.lineBreak;
53
        stream.print(str);
53
        stream.print(str);
54
    }
54
    }
55
 
55
 
56
    public void print(double d) {
56
    public void print(double d) {
57
        String str = timeStamp() + d;
57
        String str = timeStamp() + d;
58
        stream.print(str);
58
        stream.print(str);
59
    }
59
    }
60
 
60
 
61
    public void println(float f) {
61
    public void println(float f) {
62
        String str = timeStamp() + f + MySystem.lineBreak;
62
        String str = timeStamp() + f + MySystem.lineBreak;
63
        stream.print(str);
63
        stream.print(str);
64
    }
64
    }
65
 
65
 
66
    public void print(float f) {
66
    public void print(float f) {
67
        String str = timeStamp() + f;
67
        String str = timeStamp() + f;
68
        stream.print(str);
68
        stream.print(str);
69
    }
69
    }
70
 
70
 
71
    public void println(char c) {
71
    public void println(char c) {
72
        String str = timeStamp() + c + MySystem.lineBreak;
72
        String str = timeStamp() + c + MySystem.lineBreak;
73
        stream.print(str);
73
        stream.print(str);
74
    }
74
    }
75
 
75
 
76
    public void print(char c) {
76
    public void print(char c) {
77
        String str = timeStamp() + c;
77
        String str = timeStamp() + c;
78
        stream.print(str);
78
        stream.print(str);
79
    }
79
    }
80
 
80
 
81
    public void println(boolean b) {
81
    public void println(boolean b) {
82
        String str = timeStamp() + b + MySystem.lineBreak;
82
        String str = timeStamp() + b + MySystem.lineBreak;
83
        stream.print(str);
83
        stream.print(str);
84
    }
84
    }
85
 
85
 
86
    public void print(boolean b) {
86
    public void print(boolean b) {
87
        String str = timeStamp() + b;
87
        String str = timeStamp() + b;
88
        stream.print(str);
88
        stream.print(str);
89
    }
89
    }
90
 
90
 
91
    public void println(int i) {
91
    public void println(int i) {
92
        String str = timeStamp() + i + MySystem.lineBreak;
92
        String str = timeStamp() + i + MySystem.lineBreak;
93
        stream.print(str);
93
        stream.print(str);
94
    }
94
    }
95
 
95
 
96
    public void print(int i) {
96
    public void print(int i) {
97
        String str = timeStamp() + i;
97
        String str = timeStamp() + i;
98
        stream.print(str);
98
        stream.print(str);
99
    }
99
    }
100
 
100
 
101
    public void println(String str) {
101
    public void println(String str) {
102
        String string = timeStamp() + (str != null ? str : "null") + MySystem.lineBreak;
102
        String string = timeStamp() + (str != null ? str : "null") + MySystem.lineBreak;
103
        stream.print(string);
103
        stream.print(string);
104
    }
104
    }
105
 
105
 
106
    public void print(String str) {
106
    public void print(String str) {
107
        String string = timeStamp() + (str != null ? str : "null");
107
        String string = timeStamp() + (str != null ? str : "null");
108
        stream.print(string);
108
        stream.print(string);
109
    }
109
    }
110
 
110
 
111
    public void println(Object obj) {
111
    public void println(Object obj) {
112
        String str = timeStamp() + (obj != null ? obj.toString() : "null") + MySystem.lineBreak;
112
        String str = timeStamp() + (obj != null ? obj.toString() : "null") + MySystem.lineBreak;
113
        stream.print(str);
113
        stream.print(str);
114
    }
114
    }
115
 
115
 
116
    public void print(Object obj) {
116
    public void print(Object obj) {
117
        String str = timeStamp() + (obj != null ? obj.toString() : "null");
117
        String str = timeStamp() + (obj != null ? obj.toString() : "null");
118
        stream.print(str);
118
        stream.print(str);
119
    }
119
    }
120
 
120
 
121
}
121
}
122
 
122