1
1
/*
2
- * Copyright (c) 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
37
37
import java .nio .file .FileSystems ;
38
38
import java .nio .file .Files ;
39
39
import java .nio .file .Path ;
40
+ import java .util .Arrays ;
40
41
import java .util .Map ;
41
- import java .util .Random ;
42
42
43
43
44
44
/**
45
45
* @test
46
46
* @summary Verify that the outputstream created for zip file entries, through the ZipFileSystem
47
47
* works fine for varying sizes of the zip file entries
48
- * @bug 8190753 8011146
48
+ * @bug 8190753 8011146 8279536
49
49
* @run testng/timeout=300 ZipFSOutputStreamTest
50
50
*/
51
51
public class ZipFSOutputStreamTest {
@@ -90,17 +90,22 @@ private Object[][] zipFSCreationEnv() {
90
90
public void testOutputStream (final Map <String , ?> env ) throws Exception {
91
91
final URI uri = URI .create ("jar:" + ZIP_FILE .toUri () );
92
92
final byte [] chunk = new byte [1024 ];
93
- new Random ().nextBytes (chunk );
93
+ // fill it with some fixed content (the fixed content will later on help ease
94
+ // the verification of the content written out)
95
+ Arrays .fill (chunk , (byte ) 42 );
94
96
try (final FileSystem zipfs = FileSystems .newFileSystem (uri , env )) {
95
97
// create the zip with varying sized entries
96
98
for (final Map .Entry <String , Long > entry : ZIP_ENTRIES .entrySet ()) {
97
99
final Path entryPath = zipfs .getPath (entry .getKey ());
98
100
if (entryPath .getParent () != null ) {
99
101
Files .createDirectories (entryPath .getParent ());
100
102
}
103
+ long start = System .currentTimeMillis ();
101
104
try (final OutputStream os = Files .newOutputStream (entryPath )) {
102
105
writeAsChunks (os , chunk , entry .getValue ());
103
106
}
107
+ System .out .println ("Wrote entry " + entryPath + " of bytes " + entry .getValue ()
108
+ + " in " + (System .currentTimeMillis () - start ) + " milli seconds" );
104
109
}
105
110
}
106
111
// now verify the written content
@@ -111,15 +116,15 @@ public void testOutputStream(final Map<String, ?> env) throws Exception {
111
116
final byte [] buf = new byte [chunk .length ];
112
117
int numRead ;
113
118
long totalRead = 0 ;
119
+ long start = System .currentTimeMillis ();
114
120
while ((numRead = is .read (buf )) != -1 ) {
115
121
totalRead += numRead ;
116
122
// verify the content
117
- for (int i = 0 , chunkoffset = (int ) ((totalRead - numRead ) % chunk .length );
118
- i < numRead ; i ++, chunkoffset ++) {
119
- Assert .assertEquals (buf [i ], chunk [chunkoffset % chunk .length ],
120
- "Unexpected content in " + entryPath );
121
- }
123
+ Assert .assertEquals (Arrays .mismatch (buf , chunk ), -1 ,
124
+ "Unexpected content in " + entryPath );
122
125
}
126
+ System .out .println ("Read entry " + entryPath + " of bytes " + totalRead
127
+ + " in " + (System .currentTimeMillis () - start ) + " milli seconds" );
123
128
Assert .assertEquals (totalRead , (long ) entry .getValue (),
124
129
"Unexpected number of bytes read from zip entry " + entryPath );
125
130
}
0 commit comments