io.bdeploy.common.cli.data.DataTableJson Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api Show documentation
Show all versions of api Show documentation
Public API including dependencies, ready to be used for integrations and plugins.
package io.bdeploy.common.cli.data;
import java.io.PrintStream;
import java.util.List;
public class DataTableJson extends DataTableBase {
DataTableJson(PrintStream output) {
super(output);
}
@Override
public void render() {
out().println("[");
for (int i = 0; i < getRows().size(); ++i) {
List row = getRows().get(i);
out().print(" { ");
int colIndex = 0;
for (int y = 0; y < row.size(); ++y) {
DataTableColumn col = getColumns().get(colIndex);
out().print(quote(col.getName()) + ": " + quote(row.get(y).data));
if (y == (row.size() - 1)) {
if (i == (getRows().size() - 1)) {
out().println(" }");
} else {
out().println(" },");
}
} else {
out().print(", ");
}
colIndex += row.get(y).span;
}
}
out().println("]");
}
static String quote(String data) {
return "\"" + data.replace("\"", "\\\"").replace("\n", "\\n").replace("\\", "\\\\") + "\"";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy