/** * Prints the given values a single record of delimiter separated values followed by the record separator. * * <p> * The values will be quoted if needed. Quotes and newLine characters will be escaped. This method adds the record * separator to the output after printing the record, so there is no need to call {@link #println()}. * </p> * * @param values * values to output. * @throws IOException * If an I/O error occurs */ public void printRecord(final Iterable<?> values) throws IOException { for (final Object value : values) { print(value); } println(); }
/** * Prints all the objects in the given JDBC result set. * * @param resultSet * result set the values to print. * @throws IOException * If an I/O error occurs * @throws SQLException * if a database access error occurs */ public void printRecords(final ResultSet resultSet) throws SQLException, IOException { final int columnCount = resultSet.getMetaData().getColumnCount(); while (resultSet.next()) { for (int i = 1; i <= columnCount; i++) { print(resultSet.getObject(i)); } println(); } } }
public String toCsv(Csv... records) { if (records != null && records.length > 0) { String[] header = records[0].getCsvHeader(); StringWriter writer = new StringWriter(); try (CSVPrinter printer = getCSVFormat().withHeader(header).print(writer)) { for (Csv record : records) { Object [] data = record.getCsvData(); if (data == null || data.length == 0) { log.debug("Skipping null or empty record"); continue; } for (Object column : data) { printer.print(objectToString(column)); } printer.println(); } } catch (IOException e) { log.error("Failed to generate CSV", e); } return writer.toString(); } return null; }
/** * Prints a record separator (line break). * * @throws IOException if printing failed */ protected void println() throws IOException { this.printer.println(); }
final Appendable out = ...; final CSVPrinter printer = CSVFormat.DEFAULT.withHeader("H1", "H2").print(out); ... while (rowIterator.hasNext()) { ... while (cellIterator.hasNext()) { ... printer.print(cell.getStringCellValue()); ... } printer.println(); }
private String toListText(List<String> values) { StringWriter writer = new StringWriter(); CSVPrinter csvWriter = new CSVPrinter(writer); csvWriter.println(values.toArray(new String[]{})); return writer.getBuffer().toString().trim(); }
private String toListText(List<String> values) { StringWriter writer = new StringWriter(); CSVPrinter csvWriter = new CSVPrinter(writer); csvWriter.println(values.toArray(new String[]{})); return writer.getBuffer().toString().trim(); }
@Override protected void initialize(List<String> columnHeaders) throws IOException { for (String columnHeader : columnHeaders) { csvPrinter.print(columnHeader); } csvPrinter.println(); }
/** * Prints the given values a single record of delimiter separated values followed by the record separator. * * <p> * The values will be quoted if needed. Quotes and newLine characters will be escaped. This method adds the record * separator to the output after printing the record, so there is no need to call {@link #println()}. * </p> * * @param values * values to output. * @throws IOException * If an I/O error occurs */ public void printRecord(final Iterable<?> values) throws IOException { for (final Object value : values) { print(value); } println(); }
/** * Prints the given values a single record of delimiter separated values followed by the record separator. * * <p> * The values will be quoted if needed. Quotes and newLine characters will be escaped. This method adds the record * separator to the output after printing the record, so there is no need to call {@link #println()}. * </p> * * @param values * values to output. * @throws IOException * If an I/O error occurs */ public void printRecord(final Iterable<?> values) throws IOException { for (final Object value : values) { print(value); } println(); }
/** * Prints all the objects in the given JDBC result set. * * @param resultSet * result set the values to print. * @throws IOException * If an I/O error occurs * @throws SQLException * if a database access error occurs */ public void printRecords(final ResultSet resultSet) throws SQLException, IOException { final int columnCount = resultSet.getMetaData().getColumnCount(); while (resultSet.next()) { for (int i = 1; i <= columnCount; i++) { print(resultSet.getObject(i)); } println(); } } }
/** * Prints the given values a single record of delimiter separated values followed by the record separator. * * <p> * The values will be quoted if needed. Quotes and newLine characters will be escaped. This method adds the record * separator to the output after printing the record, so there is no need to call {@link #println()}. * </p> * * @param values * values to output. * @throws IOException * If an I/O error occurs */ public void printRecord(final Iterable<?> values) throws IOException { for (final Object value : values) { print(value); } println(); }
/** * Prints the given values a single record of delimiter separated values followed by the record separator. * * <p> * The values will be quoted if needed. Quotes and newLine characters will be escaped. This method adds the record * separator to the output after printing the record, so there is no need to call {@link #println()}. * </p> * * @param values * values to output. * @throws IOException * If an I/O error occurs */ public void printRecord(final Object... values) throws IOException { for (final Object value : values) { print(value); } println(); }
/** * Prints all the objects in the given JDBC result set. * * @param resultSet * result set the values to print. * @throws IOException * If an I/O error occurs * @throws SQLException * if a database access error occurs */ public void printRecords(final ResultSet resultSet) throws SQLException, IOException { final int columnCount = resultSet.getMetaData().getColumnCount(); while (resultSet.next()) { for (int i = 1; i <= columnCount; i++) { print(resultSet.getObject(i)); } println(); } }
/** * Prints all the objects in the given JDBC result set. * * @param resultSet * result set the values to print. * @throws IOException * If an I/O error occurs * @throws SQLException * if a database access error occurs */ public void printRecords(final ResultSet resultSet) throws SQLException, IOException { final int columnCount = resultSet.getMetaData().getColumnCount(); while (resultSet.next()) { for (int i = 1; i <= columnCount; i++) { print(resultSet.getObject(i)); } println(); } } }
public static String beamRow2CsvLine(Row row, CSVFormat csvFormat) { StringWriter writer = new StringWriter(); try (CSVPrinter printer = csvFormat.print(writer)) { for (int i = 0; i < row.getFieldCount(); i++) { printer.print(row.getValue(i).toString()); } printer.println(); } catch (IOException e) { throw new IllegalArgumentException("encodeRecord failed!", e); } return writer.toString(); }
@Override protected void writeRow(List<Value> values) throws IOException { for (Value value : values) { if (value == null) { csvPrinter.print(null); } else { csvPrinter.print(value.getValue()); } } csvPrinter.println(); }
/** * Convert the table to a CSV string. */ protected static StringBuilder toCsv(final RowSortedTable<Long, String, Double> table) throws IOException { final String columnNames[] = table.columnKeySet().toArray(new String[]{}); final StringBuilder sb = new StringBuilder(); final CSVPrinter printer = CSVFormat.RFC4180.withHeader(columnNames).print(sb); for (long rowIndex : table.rowKeySet()) { for (String columnName : columnNames) { Double value = table.get(rowIndex, columnName); if (value == null) { value = Double.NaN; } printer.print(value); } printer.println(); } return sb; } }
@Override public void writeStart() { try { for (Column column : getRowSet().getColumns()) { csvPrinter.print(column.getName()); } csvPrinter.println(); } catch (IOException exception) { throw new OutputException(exception); } }