All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.bdeploy.common.cli.data.DataTableCsv Maven / Gradle / Ivy

Go to download

Public API including dependencies, ready to be used for integrations and plugins.

There is a newer version: 7.3.6
Show newest version
package io.bdeploy.common.cli.data;

import java.io.PrintStream;
import java.util.List;
import java.util.stream.Collectors;

import io.bdeploy.common.util.StringHelper;

public class DataTableCsv extends DataTableBase {

    DataTableCsv(PrintStream output) {
        super(output);
    }

    @Override
    public void render() {
        out().println(String.join(",", getColumns().stream().map(c -> quote(c.getLabel())).collect(Collectors.toList())));

        for (List row : getRows()) {
            for (int y = 0; y < row.size(); ++y) {
                out().print(quote(row.get(y).data));

                if (y != (row.size() - 1)) {
                    out().print(StringHelper.repeat(",", row.get(y).span));
                } else {
                    out().println();
                }
            }
        }
    }

    static String quote(String data) {
        return "\"" + data.replace("\"", "\"\"") + "\"";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy