Mercurial > hg > icedtea9-forest > jdk
changeset 5565:1ece20885be4
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
author | sherman |
---|---|
date | Tue, 08 May 2012 11:16:36 -0700 |
parents | af209a223b6b |
children | fbf98cbd2e6b 3e3017eba8ac |
files | src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java test/demo/zipfs/ZipFSTester.java test/demo/zipfs/basic.sh |
diffstat | 3 files changed, 47 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java Tue May 08 10:57:13 2012 -0700 +++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java Tue May 08 11:16:36 2012 -0700 @@ -651,7 +651,11 @@ } 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)
--- a/test/demo/zipfs/ZipFSTester.java Tue May 08 10:57:13 2012 -0700 +++ b/test/demo/zipfs/ZipFSTester.java Tue May 08 11:16:36 2012 -0700 @@ -540,6 +540,20 @@ 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 @@ 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 @@ 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 @@ 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); }
--- a/test/demo/zipfs/basic.sh Tue May 08 10:57:13 2012 -0700 +++ b/test/demo/zipfs/basic.sh Tue May 08 11:16:36 2012 -0700 @@ -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