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 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 if (timers == null)
51 {
52 throw new IllegalArgumentException("timers must not be null");
53 }
54 if (file == null)
55 {
56 throw new IllegalArgumentException("file must not be null");
57 }
58 Writer writer = null;
59 try
60 {
61 writer = new BufferedWriter(new FileWriter(file));
62 append(timers, writer);
63 }
64 finally
65 {
66 closeQuietly(writer);
67 }
68 }
69
70
71 public final void write(final Map<? extends Runnable, Timer> timers, final OutputStream outputStream) throws IOException
72 {
73 if (timers == null)
74 {
75 throw new IllegalArgumentException("timers must not be null");
76 }
77 if (outputStream == null)
78 {
79 throw new IllegalArgumentException("outputStream must not be null");
80 }
81 Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));
82 append(timers, writer);
83 writer.flush();
84 }
85
86 private static void closeQuietly(final Writer writer)
87 {
88 try
89 {
90 writer.close();
91 }
92 catch (Exception e)
93 {
94
95 }
96 }
97 }