提交 4e1eed4e authored 作者: Thomas Mueller's avatar Thomas Mueller

Android: Workaround for a problem when using read-only databases.

上级 0ab3d2ab
...@@ -21,12 +21,15 @@ import org.h2.util.IOUtils; ...@@ -21,12 +21,15 @@ import org.h2.util.IOUtils;
*/ */
public class FileObjectZip implements FileObject { public class FileObjectZip implements FileObject {
private static final byte[] SKIP_BUFFER = new byte[1024];
private ZipFile file; private ZipFile file;
private ZipEntry entry; private ZipEntry entry;
private long pos; private long pos;
private InputStream in; private InputStream in;
private long inPos; private long inPos;
private long length; private long length;
private boolean skipUsingRead;
FileObjectZip(ZipFile file, ZipEntry entry) { FileObjectZip(ZipFile file, ZipEntry entry) {
this.file = file; this.file = file;
...@@ -58,7 +61,22 @@ public class FileObjectZip implements FileObject { ...@@ -58,7 +61,22 @@ public class FileObjectZip implements FileObject {
inPos = 0; inPos = 0;
} }
if (inPos < pos) { if (inPos < pos) {
IOUtils.skipFully(in, pos - inPos); long skip = pos - inPos;
if (!skipUsingRead) {
try {
IOUtils.skipFully(in, skip);
} catch (NullPointerException e) {
// workaround for Google Android
skipUsingRead = true;
}
}
if (skipUsingRead) {
while (skip > 0) {
int s = (int) Math.min(SKIP_BUFFER.length, skip);
s = in.read(SKIP_BUFFER, 0, s);
skip -= s;
}
}
inPos = pos; inPos = pos;
} }
int l = IOUtils.readFully(in, b, off, len); int l = IOUtils.readFully(in, b, off, len);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论