Search in sources :

Example 1 with Table

use of com.github.jcustenborder.kafka.connect.utils.templates.Table 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);
    }
}
Also used : Properties(java.util.Properties) TemplateHelper(com.github.jcustenborder.kafka.connect.utils.templates.TemplateHelper) StringWriter(java.io.StringWriter) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ConnectorTemplate(com.github.jcustenborder.kafka.connect.utils.templates.ConnectorTemplate) CSVWriter(com.opencsv.CSVWriter) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) Table(com.github.jcustenborder.kafka.connect.utils.templates.Table) List(java.util.List) StringReader(java.io.StringReader) Writer(java.io.Writer) IntentedWriter(com.github.jcustenborder.kafka.connect.utils.templates.IntentedWriter) BufferedReader(java.io.BufferedReader) Joiner(com.google.common.base.Joiner) StringWriter(java.io.StringWriter) IntentedWriter(com.github.jcustenborder.kafka.connect.utils.templates.IntentedWriter) CSVWriter(com.opencsv.CSVWriter) IOException(java.io.IOException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ConnectorTemplate (com.github.jcustenborder.kafka.connect.utils.templates.ConnectorTemplate)1 IntentedWriter (com.github.jcustenborder.kafka.connect.utils.templates.IntentedWriter)1 Table (com.github.jcustenborder.kafka.connect.utils.templates.Table)1 TemplateHelper (com.github.jcustenborder.kafka.connect.utils.templates.TemplateHelper)1 Joiner (com.google.common.base.Joiner)1 CSVWriter (com.opencsv.CSVWriter)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 LineNumberReader (java.io.LineNumberReader)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 Collectors (java.util.stream.Collectors)1