io.bdeploy.common.cli.data.DataResultText 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.
The newest version!
package io.bdeploy.common.cli.data;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Map;
import io.bdeploy.common.util.StringHelper;
class DataResultText extends DataResultBase {
DataResultText(PrintStream output) {
super(output);
}
@Override
public void render() {
DataTable table = DataFormat.TEXT.createTable(out());
table.setLineWrapHint(true);
if (getThrowable() != null) {
table.setCaption(getMessage() != null ? getMessage() : "Error");
table.setHideHeadersHint(true);
table.column(new DataTableColumn.Builder("Error").setMinWidth(100).build());
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
try (PrintWriter pw = new PrintWriter(baos, false, StringHelper.DEFAULT_CHARSET)) {
getThrowable().printStackTrace(pw);
}
try (BufferedReader br = new BufferedReader(
new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()), StringHelper.DEFAULT_CHARSET))) {
String line = br.readLine();
do {
table.row().cell(line).build();
} while ((line = br.readLine()) != null);
}
} catch (IOException e) {
out().println("ERROR: Cannot display error");
}
} else {
table.column(new DataTableColumn.Builder("Result Field").setMinWidth(25).build());
table.column(new DataTableColumn.Builder("Result Value").setMinWidth(50).build());
if (getMessage() != null) {
table.row().cell("Message").cell(getMessage()).build();
}
for (Map.Entry entry : getFields().entrySet()) {
table.row().cell(entry.getKey()).cell(entry.getValue()).build();
}
}
table.render();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy