use of org.jkiss.dbeaver.model.data.DBDContentStorage in project dbeaver by serge-rider.
the class DialogUtils method loadFromFile.
public static boolean loadFromFile(final IValueController controller) {
if (!(controller.getValue() instanceof DBDContent)) {
log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
return false;
}
Shell shell = UIUtils.getShell(controller.getValueSite());
final File openFile = openFile(shell);
if (openFile == null) {
return false;
}
final DBDContent value = (DBDContent) controller.getValue();
DBeaverUI.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DBDContentStorage storage;
if (ContentUtils.isTextContent(value)) {
storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile, GeneralUtils.UTF8_ENCODING);
} else {
storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile);
}
value.updateContents(monitor, storage);
controller.updateValue(value, true);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
return true;
}
use of org.jkiss.dbeaver.model.data.DBDContentStorage in project dbeaver by serge-rider.
the class BinaryPanelEditor method primeEditorValue.
@Override
public void primeEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull HexEditControl control, @NotNull DBDContent value) throws DBException {
monitor.beginTask("Prime content value", 1);
try {
DBDContentStorage data = value.getContents(monitor);
String charset = null;
monitor.subTask("Read binary value");
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
if (data != null) {
try (InputStream contentStream = data.getContentStream()) {
ContentUtils.copyStreams(contentStream, -1, buffer, monitor);
}
charset = data.getCharset();
} else {
charset = DBValueFormatting.getDefaultBinaryFileEncoding(value.getDataSource());
}
control.setContent(buffer.toByteArray(), charset);
} catch (IOException e) {
throw new DBException("Error reading stream value", e);
} finally {
monitor.done();
}
}
use of org.jkiss.dbeaver.model.data.DBDContentStorage in project dbeaver by serge-rider.
the class ImagePanelEditor method primeEditorValue.
@Override
public void primeEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull ImageViewer control, @NotNull DBDContent value) throws DBException {
monitor.subTask("Read image value");
DBDContentStorage data = value.getContents(monitor);
if (data != null) {
try (InputStream contentStream = data.getContentStream()) {
if (!control.loadImage(contentStream)) {
throw new DBException("Can't load image: " + control.getLastError().getMessage());
}
} catch (IOException e) {
throw new DBException("Error reading stream value", e);
}
} else {
control.clearImage();
}
}
use of org.jkiss.dbeaver.model.data.DBDContentStorage in project dbeaver by serge-rider.
the class StreamTransferConsumer method saveContentToFile.
private File saveContentToFile(DBRProgressMonitor monitor, DBDContent content) throws IOException, DBCException {
DBDContentStorage contents = content.getContents(monitor);
if (contents == null) {
log.warn("Null value content");
return null;
}
if (lobDirectory == null) {
lobDirectory = new File(settings.getOutputFolder(), LOB_DIRECTORY_NAME);
if (!lobDirectory.exists()) {
if (!lobDirectory.mkdir()) {
throw new IOException("Can't create directory for CONTENT files: " + lobDirectory.getAbsolutePath());
}
}
}
lobCount++;
Boolean extractImages = (Boolean) processorProperties.get(StreamConsumerSettings.PROP_EXTRACT_IMAGES);
String fileExt = (extractImages != null && extractImages) ? ".jpg" : ".data";
//$NON-NLS-1$ //$NON-NLS-2$
File lobFile = new File(lobDirectory, outputFile.getName() + "-" + lobCount + fileExt);
try (InputStream cs = contents.getContentStream()) {
ContentUtils.saveContentToFile(cs, lobFile, monitor);
}
return lobFile;
}
use of org.jkiss.dbeaver.model.data.DBDContentStorage in project dbeaver by serge-rider.
the class DataExporterHTML method exportRow.
@Override
public void exportRow(DBCSession session, Object[] row) throws DBException, IOException {
out.write("<tr" + (rowCount++ % 2 == 0 ? " class=\"odd\"" : "") + ">");
for (int i = 0; i < row.length; i++) {
DBDAttributeBinding column = columns.get(i);
if (DBUtils.isNullValue(row[i])) {
writeTextCell(null, false);
} else if (row[i] instanceof DBDContent) {
// Content
// Inline textual content and handle binaries in some special way
DBDContent content = (DBDContent) row[i];
try {
DBDContentStorage cs = content.getContents(session.getProgressMonitor());
out.write("<td>");
if (cs != null) {
if (ContentUtils.isTextContent(content)) {
writeCellValue(cs.getContentReader());
} else {
getSite().writeBinaryData(cs);
}
}
out.write("</td>");
} finally {
content.release();
}
} else {
String stringValue = super.getValueDisplayString(column, row[i]);
boolean isImage = row[i] instanceof File && stringValue != null && stringValue.endsWith(".jpg");
if (isImage) {
writeImageCell((File) row[i]);
} else {
writeTextCell(stringValue, false);
}
}
}
out.write("</tr>\n");
}
Aggregations