提交 1358423d 编写于 作者: S serge-rider

#260 Content cache fix

上级 2bf7456b
......@@ -20,7 +20,9 @@ package org.jkiss.dbeaver.model.impl;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.data.DBDContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.IOUtils;
import java.io.*;
import java.util.Arrays;
......@@ -91,12 +93,12 @@ public class BytesContentStorage implements DBDContentStorage {
if (contentLength > Integer.MAX_VALUE) {
throw new IOException("Too big content length for memory storage: " + contentLength);
}
byte[] data = new byte[(int)contentLength];
int count = stream.read(data);
if (count >= 0 && count != contentLength) {
log.warn("Actual content length (" + count + ") is less than declared: " + contentLength);
data = Arrays.copyOf(data, count);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyStream(stream, baos);
byte[] result = baos.toByteArray();
if (result.length != contentLength) {
log.warn("Actual content length (" + result.length + ") is less than declared: " + contentLength);
}
return new BytesContentStorage(data, encoding);
return new BytesContentStorage(result, encoding);
}
}
......@@ -84,10 +84,12 @@ public class JDBCContentBLOB extends JDBCContentLOB {
DBPApplication application = dataSource.getContainer().getApplication();
if (contentLength < application.getPreferenceStore().getInt(ModelPreferences.MEMORY_CONTENT_MAX_SIZE)) {
try {
storage = BytesContentStorage.createFromStream(
blob.getBinaryStream(),
contentLength,
application.getPreferenceStore().getString(ModelPreferences.CONTENT_HEX_ENCODING));
try (InputStream bs = blob.getBinaryStream()) {
storage = BytesContentStorage.createFromStream(
bs,
contentLength,
application.getPreferenceStore().getString(ModelPreferences.CONTENT_HEX_ENCODING));
}
}
catch (SQLException e) {
throw new DBCException(e, dataSource);
......@@ -104,7 +106,9 @@ public class JDBCContentBLOB extends JDBCContentLOB {
throw new DBCException("Can't create temporary file", e);
}
try (OutputStream os = new FileOutputStream(tempFile)) {
ContentUtils.copyStreams(blob.getBinaryStream(), contentLength, os, monitor);
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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册