Subversion Repositories HomeAutomation

Rev

Rev 73 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

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