Search in sources :

Example 1 with BytesContentStorage

use of org.jkiss.dbeaver.model.impl.BytesContentStorage in project dbeaver by serge-rider.

the class BinaryPanelEditor method extractEditorValue.

@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull HexEditControl control, @NotNull DBDContent value) throws DBException {
    BinaryContent binaryContent = control.getContent();
    ByteBuffer buffer = ByteBuffer.allocate((int) binaryContent.length());
    try {
        binaryContent.get(buffer, 0);
    } catch (IOException e) {
        log.error(e);
    }
    value.updateContents(monitor, new BytesContentStorage(buffer.array(), GeneralUtils.getDefaultFileEncoding()));
}
Also used : BytesContentStorage(org.jkiss.dbeaver.model.impl.BytesContentStorage) IOException(java.io.IOException) BinaryContent(org.jkiss.dbeaver.ui.editors.binary.BinaryContent) ByteBuffer(java.nio.ByteBuffer)

Example 2 with BytesContentStorage

use of org.jkiss.dbeaver.model.impl.BytesContentStorage in project dbeaver by serge-rider.

the class ContentInlineEditor method extractEditorValue.

@Override
public Object extractEditorValue() {
    String newValue = control.getText();
    final DBDContent content = (DBDContent) valueController.getValue();
    assert content != null;
    try {
        if (isText) {
            content.updateContents(VoidProgressMonitor.INSTANCE, new StringContentStorage(newValue));
        } else {
            content.updateContents(VoidProgressMonitor.INSTANCE, new BytesContentStorage(newValue.getBytes(GeneralUtils.getDefaultFileEncoding()), GeneralUtils.getDefaultFileEncoding()));
        }
    } catch (Exception e) {
        log.error(e);
    }
    return content;
}
Also used : DBDContent(org.jkiss.dbeaver.model.data.DBDContent) BytesContentStorage(org.jkiss.dbeaver.model.impl.BytesContentStorage) StringContentStorage(org.jkiss.dbeaver.model.impl.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Example 3 with BytesContentStorage

use of org.jkiss.dbeaver.model.impl.BytesContentStorage in project dbeaver by serge-rider.

the class DBDDocumentContentProxy method updateDocument.

@Override
public void updateDocument(@NotNull DBRProgressMonitor monitor, @NotNull InputStream stream, String encoding) throws DBException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ContentUtils.copyStreams(stream, -1, baos, monitor);
        content.updateContents(monitor, new BytesContentStorage(baos.toByteArray(), encoding));
        document.updateDocument(monitor, new ByteArrayInputStream(baos.toByteArray()), encoding);
    } catch (IOException e) {
        throw new DBException("Error transforming XML document", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) BytesContentStorage(org.jkiss.dbeaver.model.impl.BytesContentStorage)

Aggregations

BytesContentStorage (org.jkiss.dbeaver.model.impl.BytesContentStorage)3 DBException (org.jkiss.dbeaver.DBException)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)1 StringContentStorage (org.jkiss.dbeaver.model.impl.StringContentStorage)1 BinaryContent (org.jkiss.dbeaver.ui.editors.binary.BinaryContent)1