Hi, I ain't got permission to publish webrevs yet. So attached is a patch produced by hg export on the jdk tree for:
7157656 (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0 Paul.
# HG changeset patch # User psandoz # Date 1334594401 -3600 # Node ID 9febc8c1dfc66571d95f5d4e0f4575958e8b3fcf # Parent 0b052b7f3f8375f127e9c4a7f49c2220fadd2b45 7157656 (zipfs) SeekableByteChannel to entry in zip file always reports its position as 0 diff -r 0b052b7f3f83 -r 9febc8c1dfc6 src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java --- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java Thu Apr 12 09:35:30 2012 -0700 +++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java Mon Apr 16 17:40:01 2012 +0100 @@ -651,7 +651,11 @@ public class ZipFileSystem extends FileS } 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) diff -r 0b052b7f3f83 -r 9febc8c1dfc6 test/demo/zipfs/ZipFSTester.java --- a/test/demo/zipfs/ZipFSTester.java Thu Apr 12 09:35:30 2012 -0700 +++ b/test/demo/zipfs/ZipFSTester.java Mon Apr 16 17:40:01 2012 +0100 @@ -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); }