| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
package org.dishevelled.timer.report; |
| 26 | |
|
| 27 | |
import java.io.BufferedWriter; |
| 28 | |
import java.io.File; |
| 29 | |
import java.io.FileWriter; |
| 30 | |
import java.io.IOException; |
| 31 | |
import java.io.OutputStream; |
| 32 | |
import java.io.OutputStreamWriter; |
| 33 | |
import java.io.Writer; |
| 34 | |
|
| 35 | |
import java.util.Map; |
| 36 | |
|
| 37 | |
import org.dishevelled.timer.Timer; |
| 38 | |
import org.dishevelled.timer.TimerReport; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | 10 | abstract class AbstractTimerReport |
| 44 | |
implements TimerReport |
| 45 | |
{ |
| 46 | |
|
| 47 | |
|
| 48 | |
public final void write(final Map<? extends Runnable, Timer> timers, final File file) throws IOException |
| 49 | |
{ |
| 50 | 8 | if (timers == null) |
| 51 | |
{ |
| 52 | 4 | throw new IllegalArgumentException("timers must not be null"); |
| 53 | |
} |
| 54 | 4 | if (file == null) |
| 55 | |
{ |
| 56 | 2 | throw new IllegalArgumentException("file must not be null"); |
| 57 | |
} |
| 58 | 2 | Writer writer = null; |
| 59 | |
try |
| 60 | |
{ |
| 61 | 2 | writer = new BufferedWriter(new FileWriter(file)); |
| 62 | 2 | append(timers, writer); |
| 63 | |
} |
| 64 | |
finally |
| 65 | |
{ |
| 66 | 2 | closeQuietly(writer); |
| 67 | 2 | } |
| 68 | 2 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
public final void write(final Map<? extends Runnable, Timer> timers, final OutputStream outputStream) throws IOException |
| 72 | |
{ |
| 73 | 8 | if (timers == null) |
| 74 | |
{ |
| 75 | 4 | throw new IllegalArgumentException("timers must not be null"); |
| 76 | |
} |
| 77 | 4 | if (outputStream == null) |
| 78 | |
{ |
| 79 | 2 | throw new IllegalArgumentException("outputStream must not be null"); |
| 80 | |
} |
| 81 | 2 | Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream)); |
| 82 | 2 | append(timers, writer); |
| 83 | 2 | writer.flush(); |
| 84 | 2 | } |
| 85 | |
|
| 86 | |
private static void closeQuietly(final Writer writer) |
| 87 | |
{ |
| 88 | |
try |
| 89 | |
{ |
| 90 | 2 | writer.close(); |
| 91 | |
} |
| 92 | 0 | catch (Exception e) |
| 93 | |
{ |
| 94 | |
|
| 95 | 2 | } |
| 96 | 2 | } |
| 97 | |
} |