/** * Prints all the objects in the given array. * * @param values * the values to print. * @throws IOException * If an I/O error occurs */ public void printRecords(final Object[] values) throws IOException { for (final Object value : values) { if (value instanceof Object[]) { this.printRecord((Object[]) value); } else if (value instanceof Iterable) { this.printRecord((Iterable<?>) value); } else { this.printRecord(value); } } }
/** * Prints all the objects in the given collection. * * @param values * the values to print. * @throws IOException * If an I/O error occurs */ public void printRecords(final Iterable<?> values) throws IOException { for (final Object value : values) { if (value instanceof Object[]) { this.printRecord((Object[]) value); } else if (value instanceof Iterable) { this.printRecord((Iterable<?>) value); } else { this.printRecord(value); } } }
/** * Formats the specified values. * * @param values * the values to format * @return the formatted values */ public String format(final Object... values) { final StringWriter out = new StringWriter(); try { new CSVPrinter(out, this).printRecord(values); return out.toString().trim(); } catch (final IOException e) { // should not happen because a StringWriter does not do IO. throw new IllegalStateException(e); } }
public static void write(Writer writer,List<Object[]> rows) throws NestedIOException { CSVPrinter printer = null; try{ printer = new CSVPrinter(writer, CSVFormat.DEFAULT); for(Object[] row : rows){ printer.printRecord(row); } }catch(IOException e){ throw Exceptions.wrap(e); }finally{ IO.close(writer); IO.close(printer); } }