use of org.jkiss.dbeaver.model.data.storage.TemporaryContentStorage in project dbeaver by dbeaver.
the class ContentEditorInput method updateContentFromFile.
public void updateContentFromFile(DBRProgressMonitor monitor, Object value) throws DBException {
if (valueController.isReadOnly()) {
throw new DBCException("Can't update read-only value");
}
if (value instanceof DBDContent) {
DBDContent content = (DBDContent) value;
DBDContentStorage storage = content.getContents(monitor);
if (storage instanceof DBDContentStorageLocal) {
// Nothing to update - we use content's storage
content.updateContents(monitor, storage);
contentDetached = true;
} else if (storage instanceof DBDContentCached) {
// Create new storage and pass it to content
try (FileInputStream is = new FileInputStream(contentFile)) {
if (ContentUtils.isTextContent(content)) {
try (Reader reader = new InputStreamReader(is, fileCharset)) {
storage = StringContentStorage.createFromReader(reader);
}
} else {
storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
}
// StringContentStorage.
contentDetached = content.updateContents(monitor, storage);
} catch (IOException e) {
throw new DBException("Error reading content from file", e);
}
} else {
// Create new storage and pass it to content
storage = new TemporaryContentStorage(DBWorkbench.getPlatform(), contentFile, fileCharset);
contentDetached = content.updateContents(monitor, storage);
}
} else if (stringStorage != null) {
// Just read as string
valueController.updateValue(stringStorage.getString(), false);
contentDetached = true;
}
}
use of org.jkiss.dbeaver.model.data.storage.TemporaryContentStorage in project dbeaver by dbeaver.
the class JDBCContentCLOB method getContents.
@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
if (storage == null && clob != null) {
long contentLength = getContentLength();
DBPPlatform platform = executionContext.getDataSource().getContainer().getPlatform();
if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try {
String subString = clob.getSubString(1, (int) contentLength);
storage = new JDBCContentChars(executionContext, subString);
} catch (Exception e) {
log.debug("Can't get CLOB as substring", e);
try {
storage = StringContentStorage.createFromReader(clob.getCharacterStream(), contentLength);
} catch (IOException e1) {
throw new DBCException("IO error while reading content", e);
} catch (Throwable e1) {
throw new DBCException(e, executionContext);
}
}
} else {
// Create new local storage
File tempFile;
try {
tempFile = ContentUtils.createTempContentFile(monitor, platform, "clob" + clob.hashCode());
} catch (IOException e) {
throw new DBCException("Can't create temp file", e);
}
try (Writer os = new OutputStreamWriter(new FileOutputStream(tempFile), getDefaultEncoding())) {
ContentUtils.copyStreams(clob.getCharacterStream(), contentLength, os, monitor);
} catch (IOException e) {
ContentUtils.deleteTempFile(tempFile);
throw new DBCException("IO error while copying content", e);
} catch (Throwable e) {
ContentUtils.deleteTempFile(tempFile);
throw new DBCException(e, executionContext);
}
this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
}
// Free lob - we don't need it anymore
releaseClob();
}
return storage;
}
use of org.jkiss.dbeaver.model.data.storage.TemporaryContentStorage in project dbeaver by dbeaver.
the class OracleContentBFILE method getContents.
@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
if (storage == null && bfile != null) {
try {
openFile();
long contentLength = getContentLength();
DBPPlatform platform = executionContext.getDataSource().getContainer().getPlatform();
if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try {
try (InputStream bs = getInputStream()) {
storage = BytesContentStorage.createFromStream(bs, contentLength, getDefaultEncoding());
}
} catch (IOException e) {
throw new DBCException("IO error while reading content", e);
}
} else {
// Create new local storage
File tempFile;
try {
tempFile = ContentUtils.createTempContentFile(monitor, platform, "blob" + bfile.hashCode());
} catch (IOException e) {
throw new DBCException("Can't create temporary file", e);
}
try (OutputStream os = new FileOutputStream(tempFile)) {
try (InputStream bs = getInputStream()) {
ContentUtils.copyStreams(bs, contentLength, os, monitor);
}
} catch (IOException e) {
ContentUtils.deleteTempFile(tempFile);
throw new DBCException("IO error while copying stream", e);
} catch (Throwable e) {
ContentUtils.deleteTempFile(tempFile);
throw new DBCException(e, executionContext);
}
this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
}
// Free blob - we don't need it anymore
releaseBlob();
} finally {
closeFile();
}
}
return storage;
}
Aggregations