use of org.jkiss.dbeaver.model.impl.TemporaryContentStorage in project dbeaver by serge-rider.
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 = dataSource.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, dataSource);
}
this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
}
// Free blob - we don't need it anymore
releaseBlob();
} finally {
closeFile();
}
}
return storage;
}
use of org.jkiss.dbeaver.model.impl.TemporaryContentStorage in project dbeaver by serge-rider.
the class ContentEditorInput method updateContentFromFile.
public void updateContentFromFile(IProgressMonitor monitor) throws DBException {
if (valueController.isReadOnly()) {
throw new DBCException("Can't update read-only value");
}
DBRProgressMonitor localMonitor = RuntimeUtils.makeMonitor(monitor);
DBDContent content = getContent();
DBDContentStorage storage = content.getContents(localMonitor);
if (storage instanceof DBDContentStorageLocal) {
// Nothing to update - we user content's storage
contentDetached = true;
} else if (storage instanceof DBDContentCached) {
// Create new storage and pass it to content
try (FileInputStream is = new FileInputStream(contentFile)) {
if (storage instanceof StringContentStorage) {
try (Reader reader = new InputStreamReader(is, fileCharset)) {
storage = StringContentStorage.createFromReader(reader);
}
} else {
storage = BytesContentStorage.createFromStream(is, contentFile.length(), fileCharset);
}
//StringContentStorage.
contentDetached = content.updateContents(localMonitor, 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(DBeaverCore.getInstance(), contentFile, fileCharset);
contentDetached = content.updateContents(localMonitor, storage);
}
}
use of org.jkiss.dbeaver.model.impl.TemporaryContentStorage in project dbeaver by serge-rider.
the class JDBCContentBLOB method getContents.
@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
if (storage == null && blob != null) {
long contentLength = getContentLength();
DBPPlatform platform = dataSource.getContainer().getPlatform();
if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try {
try (InputStream bs = blob.getBinaryStream()) {
storage = BytesContentStorage.createFromStream(bs, contentLength, getDefaultEncoding());
}
} catch (IOException e) {
throw new DBCException("IO error while reading content", e);
} catch (Throwable e) {
throw new DBCException(e, dataSource);
}
} else {
// Create new local storage
File tempFile;
try {
tempFile = ContentUtils.createTempContentFile(monitor, platform, "blob" + blob.hashCode());
} catch (IOException e) {
throw new DBCException("Can't create temporary file", e);
}
try (OutputStream os = new FileOutputStream(tempFile)) {
try (InputStream bs = blob.getBinaryStream()) {
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, dataSource);
}
this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
}
// Free blob - we don't need it anymore
releaseBlob();
}
return storage;
}
use of org.jkiss.dbeaver.model.impl.TemporaryContentStorage in project dbeaver by serge-rider.
the class JDBCContentCLOB method getContents.
@Override
public DBDContentStorage getContents(DBRProgressMonitor monitor) throws DBCException {
if (storage == null && clob != null) {
long contentLength = getContentLength();
DBPPlatform platform = dataSource.getContainer().getPlatform();
if (contentLength < platform.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try {
storage = StringContentStorage.createFromReader(clob.getCharacterStream(), contentLength);
} catch (IOException e) {
throw new DBCException("IO error while reading content", e);
} catch (Throwable e) {
throw new DBCException(e, dataSource);
}
} 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, dataSource);
}
this.storage = new TemporaryContentStorage(platform, tempFile, getDefaultEncoding());
}
// Free lob - we don't need it anymore
releaseClob();
}
return storage;
}
Aggregations