7157656: (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0
Updated SeekableByteChannel.read() to count the bytes read correctly Reviewed-by: sherman
This commit is contained in:
parent
c8da8f2595
commit
30fb5c8146
@ -651,7 +651,11 @@ public class ZipFileSystem extends FileSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int read(ByteBuffer dst) throws IOException {
|
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)
|
public SeekableByteChannel truncate(long size)
|
||||||
|
@ -540,6 +540,20 @@ public class ZipFSTester {
|
|||||||
bbSrc.flip();
|
bbSrc.flip();
|
||||||
bbDst.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) {
|
} catch (IOException x) {
|
||||||
x.printStackTrace();
|
x.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -587,6 +601,20 @@ public class ZipFSTester {
|
|||||||
dstCh.write(bb);
|
dstCh.write(bb);
|
||||||
bb.clear();
|
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)) {
|
try (SeekableByteChannel sbc = Files.newByteChannel(path)) {
|
||||||
System.out.printf(" sbc[0]: pos=%d, size=%d%n", sbc.position(), sbc.size());
|
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());
|
bb = ByteBuffer.allocate((int)sbc.size());
|
||||||
n = sbc.read(bb);
|
n = sbc.read(bb);
|
||||||
System.out.printf(" sbc[1]: read=%d, pos=%d, size=%d%n",
|
System.out.printf(" sbc[1]: read=%d, pos=%d, size=%d%n",
|
||||||
n, sbc.position(), sbc.size());
|
n, sbc.position(), sbc.size());
|
||||||
|
if (sbc.position() != sbc.size()) {
|
||||||
|
throw new RuntimeException("CHECK FAILED!");
|
||||||
|
}
|
||||||
bb2 = ByteBuffer.allocate((int)sbc.size());
|
bb2 = ByteBuffer.allocate((int)sbc.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,10 +664,16 @@ public class ZipFSTester {
|
|||||||
sbc.position(N);
|
sbc.position(N);
|
||||||
System.out.printf(" sbc[2]: pos=%d, size=%d%n",
|
System.out.printf(" sbc[2]: pos=%d, size=%d%n",
|
||||||
sbc.position(), sbc.size());
|
sbc.position(), sbc.size());
|
||||||
|
if (sbc.position() != N) {
|
||||||
|
throw new RuntimeException("CHECK FAILED!");
|
||||||
|
}
|
||||||
bb2.limit(100);
|
bb2.limit(100);
|
||||||
n = sbc.read(bb2);
|
n = sbc.read(bb2);
|
||||||
System.out.printf(" sbc[3]: read=%d, pos=%d, size=%d%n",
|
System.out.printf(" sbc[3]: read=%d, pos=%d, size=%d%n",
|
||||||
n, sbc.position(), sbc.size());
|
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",
|
System.out.printf(" sbc[4]: bb[%d]=%d, bb1[0]=%d%n",
|
||||||
N, bb.get(N) & 0xff, bb2.get(0) & 0xff);
|
N, bb.get(N) & 0xff, bb2.get(0) & 0xff);
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#
|
#
|
||||||
# @test
|
# @test
|
||||||
# @bug 6990846 7009092 7009085 7015391 7014948 7005986 7017840 7007596
|
# @bug 6990846 7009092 7009085 7015391 7014948 7005986 7017840 7007596
|
||||||
|
# 7157656
|
||||||
# @summary Test ZipFileSystem demo
|
# @summary Test ZipFileSystem demo
|
||||||
# @build Basic PathOps ZipFSTester
|
# @build Basic PathOps ZipFSTester
|
||||||
# @run shell basic.sh
|
# @run shell basic.sh
|
||||||
|
Loading…
Reference in New Issue
Block a user