提交 c5d4f799 编写于 作者: S sherman

7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0

Summary: updated SeekableByteChannel.read() to count the bytes read correctly
Reviewed-by: sherman
Contributed-by: paul.sandoz@oracle.com
上级 ca584342
......@@ -651,7 +651,11 @@ public class ZipFileSystem extends FileSystem {
}
public int read(ByteBuffer dst) throws IOException {
return rbc.read(dst);
int n = rbc.read(dst);
if (n > 0) {
read += n;
}
return n;
}
public SeekableByteChannel truncate(long size)
......
......@@ -540,6 +540,20 @@ public class ZipFSTester {
bbSrc.flip();
bbDst.flip();
}
// Check if source read position is at the end
if (chSrc.position() != chSrc.size()) {
System.out.printf("src[%s]: size=%d, position=%d%n",
chSrc.toString(), chSrc.size(), chSrc.position());
throw new RuntimeException("CHECK FAILED!");
}
// Check if destination read position is at the end
if (chDst.position() != chDst.size()) {
System.out.printf("dst[%s]: size=%d, position=%d%n",
chDst.toString(), chDst.size(), chDst.position());
throw new RuntimeException("CHECK FAILED!");
}
} catch (IOException x) {
x.printStackTrace();
}
......@@ -587,6 +601,20 @@ public class ZipFSTester {
dstCh.write(bb);
bb.clear();
}
// Check if source read position is at the end
if (srcCh.position() != srcCh.size()) {
System.out.printf("src[%s]: size=%d, position=%d%n",
srcCh.toString(), srcCh.size(), srcCh.position());
throw new RuntimeException("CHECK FAILED!");
}
// Check if destination write position is at the end
if (dstCh.position() != dstCh.size()) {
System.out.printf("dst[%s]: size=%d, position=%d%n",
dstCh.toString(), dstCh.size(), dstCh.position());
throw new RuntimeException("CHECK FAILED!");
}
}
}
......@@ -616,10 +644,17 @@ public class ZipFSTester {
try (SeekableByteChannel sbc = Files.newByteChannel(path)) {
System.out.printf(" sbc[0]: pos=%d, size=%d%n", sbc.position(), sbc.size());
if (sbc.position() != 0) {
throw new RuntimeException("CHECK FAILED!");
}
bb = ByteBuffer.allocate((int)sbc.size());
n = sbc.read(bb);
System.out.printf(" sbc[1]: read=%d, pos=%d, size=%d%n",
n, sbc.position(), sbc.size());
if (sbc.position() != sbc.size()) {
throw new RuntimeException("CHECK FAILED!");
}
bb2 = ByteBuffer.allocate((int)sbc.size());
}
......@@ -629,10 +664,16 @@ public class ZipFSTester {
sbc.position(N);
System.out.printf(" sbc[2]: pos=%d, size=%d%n",
sbc.position(), sbc.size());
if (sbc.position() != N) {
throw new RuntimeException("CHECK FAILED!");
}
bb2.limit(100);
n = sbc.read(bb2);
System.out.printf(" sbc[3]: read=%d, pos=%d, size=%d%n",
n, sbc.position(), sbc.size());
if (n < 0 || sbc.position() != (N + n)) {
throw new RuntimeException("CHECK FAILED!");
}
System.out.printf(" sbc[4]: bb[%d]=%d, bb1[0]=%d%n",
N, bb.get(N) & 0xff, bb2.get(0) & 0xff);
}
......
......@@ -22,6 +22,7 @@
#
# @test
# @bug 6990846 7009092 7009085 7015391 7014948 7005986 7017840 7007596
# 7157656
# @summary Test ZipFileSystem demo
# @build Basic PathOps ZipFSTester
# @run shell basic.sh
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册