1 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 23 public class CSVPrinter extends AbstractTablePrinter 24 { 25 private String delim = ","; 26 private boolean printHeaders = true; 27 28 public CSVPrinter(Writer out) 29 { 30 super(out); 31 } 32 33 public CSVPrinter(OutputStream out) 34 { 35 super(out); 36 } 37 38 public void print(Collection stats) 39 { 40 try 41 { 42 String [][] table = getTable(stats); 43 int i = (printHeaders ? 0 : 1); 44 for (; i < table.length; i++) 45 { 46 for (int j = 0; j < table[0].length; j++) 47 { 48 print(table[i][j]); 49 if (j + 1 != table[i].length) 50 { 51 print(delim); 52 } 53 } 54 println(); 55 } 56 } 57 catch (Throwable e) 58 { 59 e.printStackTrace(); 60 } 61 } 62 63 public boolean isPrintHeaders() 64 { 65 return printHeaders; 66 } 67 68 public void setPrintHeaders(boolean printHeaders) 69 { 70 this.printHeaders = printHeaders; 71 } 72 } 73 | Popular Tags |