01: /*
02: * $Id: CSVPrinter.java 10529 2008-01-25 05:58:36Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: * <code>CSVPrinter</code> prints service stats in CSV format
19: */
20: public class CSVPrinter extends AbstractTablePrinter {
21: private String delim = ",";
22: private boolean printHeaders = true;
23:
24: public CSVPrinter(Writer out) {
25: super (out);
26: }
27:
28: public CSVPrinter(OutputStream out) {
29: super (out);
30: }
31:
32: public void print(Collection stats) {
33: try {
34: String[][] table = getTable(stats);
35: int i = (printHeaders ? 0 : 1);
36: for (; i < table.length; i++) {
37: for (int j = 0; j < table[0].length; j++) {
38: print(table[i][j]);
39: if (j + 1 != table[i].length) {
40: print(delim);
41: }
42: }
43: println();
44: }
45: } catch (Throwable e) {
46: // TODO MULE-863: Unlikely to be sufficient
47: // (and nothing explicitly thrown above)
48: e.printStackTrace();
49: }
50: }
51:
52: public boolean isPrintHeaders() {
53: return printHeaders;
54: }
55:
56: public void setPrintHeaders(boolean printHeaders) {
57: this.printHeaders = printHeaders;
58: }
59: }
|