use of com.github.jcustenborder.kafka.connect.utils.templates.IntentedWriter in project connect-utils by jcustenborder.
the class RstTemplateHelper method table.
public String table(Table table) {
try (StringWriter writer = new StringWriter()) {
try (IntentedWriter printWriter = new IntentedWriter(writer)) {
printWriter.write(String.format(".. csv-table:: %s\n", table.getTitle()));
printWriter.increase();
printWriter.write(String.format(":header: \"%s\"\n", Joiner.on("\", \"").join(table.getHeaders())));
printWriter.write(":widths: auto\n");
printWriter.println();
try (CSVWriter csvWriter = new CSVWriter(printWriter)) {
final List<String[]> rows = table.getRowData().stream().map(strings -> strings.toArray(new String[strings.size()])).collect(Collectors.toList());
csvWriter.writeAll(rows);
}
}
return writer.toString();
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
Aggregations