提交 5eb04dac authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 356: for Blob objects, InputStream.skip() returned 0, causing EOFException…

Issue 356: for Blob objects, InputStream.skip() returned 0, causing EOFException in Blob.getBytes(.., ..).
上级 de81a806
......@@ -295,18 +295,20 @@ public class LobStorage {
}
public long skip(long n) throws IOException {
n -= skipSmall(n);
if (n > BLOCK_LENGTH) {
long toPos = length - remainingBytes + n;
long remaining = n;
remaining -= skipSmall(remaining);
if (remaining > BLOCK_LENGTH) {
long toPos = length - remainingBytes + remaining;
try {
long[] seqPos = skipBuffer(lob, toPos);
if (seqPos == null) {
return super.skip(n);
remaining -= super.skip(remaining);
return n - remaining;
}
seq = (int) seqPos[0];
long p = seqPos[1];
remainingBytes = length - p;
n = toPos - p;
remaining = toPos - p;
} catch (SQLException e) {
throw DbException.convertToIOException(e);
}
......@@ -314,8 +316,9 @@ public class LobStorage {
buffer = null;
}
fillBuffer();
n -= skipSmall(n);
return super.skip(n);
remaining -= skipSmall(remaining);
remaining -= super.skip(remaining);
return n - remaining;
}
private int skipSmall(long n) {
......
......@@ -55,6 +55,7 @@ public class TestLob extends TestBase {
}
public void test() throws Exception {
testLobSkip();
testLobSkipPastEnd();
testCreateIndexOnLob();
testBlobInputStreamSeek(true);
......@@ -101,6 +102,21 @@ public class TestLob extends TestBase {
FileUtils.deleteRecursive(TEMP_DIR, true);
}
private void testLobSkip() throws Exception {
deleteDb("lob");
Connection conn;
conn = getConnection("lob");
Statement stat = conn.createStatement();
stat.executeUpdate("create table test(x blob) as select secure_rand(1000)");
ResultSet rs = stat.executeQuery("select * from test");
rs.next();
Blob b = rs.getBlob(1);
byte[] test = b.getBytes(5 + 1, 1000 - 5);
assertEquals(1000 - 5, test.length);
stat.execute("drop table test");
conn.close();
}
private void testLobSkipPastEnd() throws Exception {
if (config.memory) {
return;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论