Search in sources :

Example 1 with BytesContentStorage

use of org.jkiss.dbeaver.model.data.storage.BytesContentStorage in project dbeaver by dbeaver.

the class BinaryPanelEditor method extractEditorValue.

@Override
public void extractEditorValue(@NotNull DBRProgressMonitor monitor, @NotNull HexEditControl control, @NotNull DBDContent value) throws DBException {
    BinaryContent binaryContent = control.getContent();
    if (binaryContent != null) {
        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.data.storage.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.data.storage.BytesContentStorage in project dbeaver by dbeaver.

the class DBDDocumentContentProxy method updateDocument.

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

Example 3 with BytesContentStorage

use of org.jkiss.dbeaver.model.data.storage.BytesContentStorage in project dbeaver by dbeaver.

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(new VoidProgressMonitor(), new StringContentStorage(newValue));
        } else {
            content.updateContents(new VoidProgressMonitor(), 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.data.storage.BytesContentStorage) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Example 4 with BytesContentStorage

use of org.jkiss.dbeaver.model.data.storage.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();
    if (binaryContent != null) {
        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.data.storage.BytesContentStorage) IOException(java.io.IOException) BinaryContent(org.jkiss.dbeaver.ui.editors.binary.BinaryContent) ByteBuffer(java.nio.ByteBuffer)

Example 5 with BytesContentStorage

use of org.jkiss.dbeaver.model.data.storage.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(new VoidProgressMonitor(), new StringContentStorage(newValue));
        } else {
            content.updateContents(new VoidProgressMonitor(), 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.data.storage.BytesContentStorage) VoidProgressMonitor(org.jkiss.dbeaver.model.runtime.VoidProgressMonitor) StringContentStorage(org.jkiss.dbeaver.model.data.storage.StringContentStorage) DBException(org.jkiss.dbeaver.DBException)

Aggregations

BytesContentStorage (org.jkiss.dbeaver.model.data.storage.BytesContentStorage)6 DBException (org.jkiss.dbeaver.DBException)4 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 DBDContent (org.jkiss.dbeaver.model.data.DBDContent)2 StringContentStorage (org.jkiss.dbeaver.model.data.storage.StringContentStorage)2 VoidProgressMonitor (org.jkiss.dbeaver.model.runtime.VoidProgressMonitor)2 BinaryContent (org.jkiss.dbeaver.ui.editors.binary.BinaryContent)2