From c5d4f799ed42fd4b39a163461f17e05fb3cf372e Mon Sep 17 00:00:00 2001 From: sherman Date: Tue, 8 May 2012 11:16:36 -0700 Subject: [PATCH] 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 --- .../src/com/sun/nio/zipfs/ZipFileSystem.java | 6 ++- test/demo/zipfs/ZipFSTester.java | 41 +++++++++++++++++++ test/demo/zipfs/basic.sh | 1 + 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java index d68388a97..44d3e8099 100644 --- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java +++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java @@ -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) diff --git a/test/demo/zipfs/ZipFSTester.java b/test/demo/zipfs/ZipFSTester.java index 4969c21f3..0d512cc1f 100644 --- a/test/demo/zipfs/ZipFSTester.java +++ b/test/demo/zipfs/ZipFSTester.java @@ -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); } diff --git a/test/demo/zipfs/basic.sh b/test/demo/zipfs/basic.sh index 40dc0c0a1..7188c181e 100644 --- a/test/demo/zipfs/basic.sh +++ b/test/demo/zipfs/basic.sh @@ -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 -- GitLab