11/*
2- * Copyright (c) 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2022 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3535import java .nio .file .FileSystems ;
3636import java .nio .file .Files ;
3737import java .nio .file .Path ;
38+ import java .util .Arrays ;
3839import java .util .Map ;
39- import java .util .Random ;
4040
4141
4242/**
4343 * @test
4444 * @summary Verify that the outputstream created for zip file entries, through the ZipFileSystem
4545 * works fine for varying sizes of the zip file entries
46- * @bug 8190753 8011146
46+ * @bug 8190753 8011146 8279536
4747 * @run testng/timeout=300 ZipFSOutputStreamTest
4848 */
4949public class ZipFSOutputStreamTest {
@@ -87,17 +87,22 @@ private Object[][] zipFSCreationEnv() {
8787 @ Test (dataProvider = "zipFSCreationEnv" )
8888 public void testOutputStream (final Map <String , ?> env ) throws Exception {
8989 final byte [] chunk = new byte [1024 ];
90- new Random ().nextBytes (chunk );
90+ // fill it with some fixed content (the fixed content will later on help ease
91+ // the verification of the content written out)
92+ Arrays .fill (chunk , (byte ) 42 );
9193 try (final FileSystem zipfs = FileSystems .newFileSystem (ZIP_FILE , env )) {
9294 // create the zip with varying sized entries
9395 for (final Map .Entry <String , Long > entry : ZIP_ENTRIES .entrySet ()) {
9496 final Path entryPath = zipfs .getPath (entry .getKey ());
9597 if (entryPath .getParent () != null ) {
9698 Files .createDirectories (entryPath .getParent ());
9799 }
100+ long start = System .currentTimeMillis ();
98101 try (final OutputStream os = Files .newOutputStream (entryPath )) {
99102 writeAsChunks (os , chunk , entry .getValue ());
100103 }
104+ System .out .println ("Wrote entry " + entryPath + " of bytes " + entry .getValue ()
105+ + " in " + (System .currentTimeMillis () - start ) + " milli seconds" );
101106 }
102107 }
103108 // now verify the written content
@@ -108,15 +113,15 @@ public void testOutputStream(final Map<String, ?> env) throws Exception {
108113 final byte [] buf = new byte [chunk .length ];
109114 int numRead ;
110115 long totalRead = 0 ;
116+ long start = System .currentTimeMillis ();
111117 while ((numRead = is .read (buf )) != -1 ) {
112118 totalRead += numRead ;
113119 // verify the content
114- for (int i = 0 , chunkoffset = (int ) ((totalRead - numRead ) % chunk .length );
115- i < numRead ; i ++, chunkoffset ++) {
116- Assert .assertEquals (buf [i ], chunk [chunkoffset % chunk .length ],
117- "Unexpected content in " + entryPath );
118- }
120+ Assert .assertEquals (Arrays .mismatch (buf , chunk ), -1 ,
121+ "Unexpected content in " + entryPath );
119122 }
123+ System .out .println ("Read entry " + entryPath + " of bytes " + totalRead
124+ + " in " + (System .currentTimeMillis () - start ) + " milli seconds" );
120125 Assert .assertEquals (totalRead , (long ) entry .getValue (),
121126 "Unexpected number of bytes read from zip entry " + entryPath );
122127 }
0 commit comments