提交 7bdb29de authored 作者: Noel Grandin's avatar Noel Grandin

FilePathMem needs to implement read/write(Buffer,position)

otherwise client code will end up calling the version in FileBase, which
has unnecessary synchronisation
上级 79c7b389
...@@ -302,6 +302,19 @@ class FileMem extends FileBase { ...@@ -302,6 +302,19 @@ class FileMem extends FileBase {
return this; return this;
} }
@Override
public int write(ByteBuffer src, long position) throws IOException {
int len = src.remaining();
if (len == 0) {
return 0;
}
data.touch(readOnly);
data.readWrite(position, src.array(),
src.arrayOffset() + src.position(), len, true);
src.position(src.position() + len);
return len;
}
@Override @Override
public int write(ByteBuffer src) throws IOException { public int write(ByteBuffer src) throws IOException {
int len = src.remaining(); int len = src.remaining();
...@@ -315,6 +328,22 @@ class FileMem extends FileBase { ...@@ -315,6 +328,22 @@ class FileMem extends FileBase {
return len; return len;
} }
@Override
public int read(ByteBuffer dst, long position) throws IOException {
int len = dst.remaining();
if (len == 0) {
return 0;
}
long newPos = data.readWrite(position, dst.array(),
dst.arrayOffset() + dst.position(), len, false);
len = (int) (newPos - position);
if (len <= 0) {
return -1;
}
dst.position(dst.position() + len);
return len;
}
@Override @Override
public int read(ByteBuffer dst) throws IOException { public int read(ByteBuffer dst) throws IOException {
int len = dst.remaining(); int len = dst.remaining();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论