use of org.jkiss.dbeaver.model.data.DBDDocument in project dbeaver by serge-rider.
the class DataExporterJSON method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
PrintWriter out = getWriter();
if (rowNum > 0) {
out.write(",\n");
}
rowNum++;
if (isJsonDocumentResults(session.getProgressMonitor(), row)) {
DBDDocument document = (DBDDocument) row[0];
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
document.serializeDocument(session.getProgressMonitor(), buffer, StandardCharsets.UTF_8);
String jsonText = buffer.toString(StandardCharsets.UTF_8.name());
out.write(jsonText);
} else {
out.write("\t{\n");
for (int i = 0; i < columns.length; i++) {
DBDAttributeBinding column = columns[i];
String columnName = column.getLabel();
if (CommonUtils.isEmpty(columnName)) {
columnName = column.getName();
}
out.write("\t\t\"" + JSONUtils.escapeJsonString(columnName) + "\" : ");
Object cellValue = row[column.getOrdinalPosition()];
if (DBUtils.isNullValue(cellValue)) {
writeTextCell(null);
} else if (cellValue instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) cellValue;
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
try (Reader in = cs.getContentReader()) {
out.write("\"");
writeCellValue(in);
out.write("\"");
}
} else {
getSite().writeBinaryData(cs);
}
}
} finally {
content.release();
}
} else {
if (cellValue instanceof Number || cellValue instanceof Boolean) {
out.write(cellValue.toString());
} else if (cellValue instanceof Date && formatDateISO) {
writeTextCell(JSONUtils.formatDate((Date) cellValue));
} else {
writeTextCell(super.getValueDisplayString(column, cellValue));
}
}
if (i < columns.length - 1) {
out.write(",");
}
out.write("\n");
}
out.write("\t}");
}
}
use of org.jkiss.dbeaver.model.data.DBDDocument in project dbeaver by dbeaver.
the class DataExporterJSON method exportRow.
@Override
public void exportRow(DBCSession session, DBCResultSet resultSet, Object[] row) throws DBException, IOException {
PrintWriter out = getWriter();
if (rowNum > 0) {
out.write(",\n");
}
rowNum++;
if (isJsonDocumentResults(session.getProgressMonitor(), row)) {
DBDDocument document = (DBDDocument) row[0];
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
document.serializeDocument(session.getProgressMonitor(), buffer, StandardCharsets.UTF_8);
String jsonText = buffer.toString(StandardCharsets.UTF_8.name());
out.write(jsonText);
} else {
out.write("\t{\n");
for (int i = 0; i < columns.length; i++) {
DBDAttributeBinding column = columns[i];
String columnName = column.getLabel();
if (CommonUtils.isEmpty(columnName)) {
columnName = column.getName();
}
out.write("\t\t\"" + JSONUtils.escapeJsonString(columnName) + "\" : ");
Object cellValue = row[column.getOrdinalPosition()];
if (DBUtils.isNullValue(cellValue)) {
writeTextCell(null);
} else if (cellValue instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) cellValue;
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
try (Reader in = cs.getContentReader()) {
out.write("\"");
writeCellValue(in);
out.write("\"");
}
} else {
getSite().writeBinaryData(cs);
}
}
} finally {
content.release();
}
} else {
if (cellValue instanceof Number || cellValue instanceof Boolean) {
out.write(cellValue.toString());
} else if (cellValue instanceof Date && formatDateISO) {
writeTextCell(JSONUtils.formatDate((Date) cellValue));
} else {
writeTextCell(super.getValueDisplayString(column, cellValue));
}
}
if (i < columns.length - 1) {
out.write(",");
}
out.write("\n");
}
out.write("\t}");
}
}
Aggregations