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