1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.stats.printers; |
12 | |
|
13 | |
import java.io.OutputStream; |
14 | |
import java.io.Writer; |
15 | |
import java.util.Collection; |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
public class CSVPrinter extends AbstractTablePrinter |
21 | |
{ |
22 | 0 | private String delim = ","; |
23 | 0 | private boolean printHeaders = true; |
24 | |
|
25 | |
public CSVPrinter(Writer out) |
26 | |
{ |
27 | 0 | super(out); |
28 | 0 | } |
29 | |
|
30 | |
public CSVPrinter(OutputStream out) |
31 | |
{ |
32 | 0 | super(out); |
33 | 0 | } |
34 | |
|
35 | |
public void print(Collection stats) |
36 | |
{ |
37 | |
try |
38 | |
{ |
39 | 0 | String[][] table = getTable(stats); |
40 | 0 | int i = (printHeaders ? 0 : 1); |
41 | 0 | for (; i < table.length; i++) |
42 | |
{ |
43 | 0 | for (int j = 0; j < table[0].length; j++) |
44 | |
{ |
45 | 0 | print(table[i][j]); |
46 | 0 | if (j + 1 != table[i].length) |
47 | |
{ |
48 | 0 | print(delim); |
49 | |
} |
50 | |
} |
51 | 0 | println(); |
52 | |
} |
53 | |
} |
54 | 0 | catch (Throwable e) |
55 | |
{ |
56 | |
|
57 | |
|
58 | 0 | e.printStackTrace(); |
59 | 0 | } |
60 | 0 | } |
61 | |
|
62 | |
public boolean isPrintHeaders() |
63 | |
{ |
64 | 0 | return printHeaders; |
65 | |
} |
66 | |
|
67 | |
public void setPrintHeaders(boolean printHeaders) |
68 | |
{ |
69 | 0 | this.printHeaders = printHeaders; |
70 | 0 | } |
71 | |
} |