| 1 | package net.digitaltsunami.tmeter.record; |
| 2 | |
| 3 | import java.io.PrintStream; |
| 4 | |
| 5 | import net.digitaltsunami.tmeter.Timer; |
| 6 | import net.digitaltsunami.tmeter.TimerLogType; |
| 7 | |
| 8 | /** |
| 9 | * Record all timers to the provided output stream. |
| 10 | * |
| 11 | * @author dhagberg |
| 12 | * |
| 13 | */ |
| 14 | public class FileTimeRecorder implements TimeRecorder { |
| 15 | |
| 16 | protected final PrintStream out; |
| 17 | protected final TimerLogType logType; |
| 18 | |
| 19 | /** |
| 20 | * Create a new FileTimeRecorder with the output stream to which all timers. |
| 21 | * @param out print stream for timers. |
| 22 | */ |
| 23 | public FileTimeRecorder(PrintStream out) { |
| 24 | this(out, TimerLogType.TEXT); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Create a new FileTimeRecorder with the output stream to which all timers |
| 29 | * will be written and the format in which they will be written. |
| 30 | * |
| 31 | * @param out print stream for timers. |
| 32 | * @param logType format used to write timers to output stream. |
| 33 | */ |
| 34 | public FileTimeRecorder(PrintStream out, TimerLogType logType) { |
| 35 | super(); |
| 36 | this.out = out; |
| 37 | this.logType = logType; |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void record(Timer timer) { |
| 42 | switch (logType) { |
| 43 | case TEXT: |
| 44 | out.println(timer.toString()); |
| 45 | break; |
| 46 | |
| 47 | case CSV: |
| 48 | out.println(timer.toCsv()); |
| 49 | break; |
| 50 | |
| 51 | default: |
| 52 | break; |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | public TimerLogType getLogType() { |
| 57 | return this.logType; |
| 58 | } |
| 59 | |
| 60 | } |