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
35
35
import java .nio .file .FileSystems ;
36
36
import java .nio .file .Files ;
37
37
import java .nio .file .Path ;
38
+ import java .util .Arrays ;
38
39
import java .util .Map ;
39
- import java .util .Random ;
40
40
41
41
42
42
/**
43
43
* @test
44
44
* @summary Verify that the outputstream created for zip file entries, through the ZipFileSystem
45
45
* works fine for varying sizes of the zip file entries
46
- * @bug 8190753 8011146
46
+ * @bug 8190753 8011146 8279536
47
47
* @run testng/timeout=300 ZipFSOutputStreamTest
48
48
*/
49
49
public class ZipFSOutputStreamTest {
@@ -87,17 +87,22 @@ private Object[][] zipFSCreationEnv() {
87
87
@ Test (dataProvider = "zipFSCreationEnv" )
88
88
public void testOutputStream (final Map <String , ?> env ) throws Exception {
89
89
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 );
91
93
try (final FileSystem zipfs = FileSystems .newFileSystem (ZIP_FILE , env )) {
92
94
// create the zip with varying sized entries
93
95
for (final Map .Entry <String , Long > entry : ZIP_ENTRIES .entrySet ()) {
94
96
final Path entryPath = zipfs .getPath (entry .getKey ());
95
97
if (entryPath .getParent () != null ) {
96
98
Files .createDirectories (entryPath .getParent ());
97
99
}
100
+ long start = System .currentTimeMillis ();
98
101
try (final OutputStream os = Files .newOutputStream (entryPath )) {
99
102
writeAsChunks (os , chunk , entry .getValue ());
100
103
}
104
+ System .out .println ("Wrote entry " + entryPath + " of bytes " + entry .getValue ()
105
+ + " in " + (System .currentTimeMillis () - start ) + " milli seconds" );
101
106
}
102
107
}
103
108
// now verify the written content
@@ -108,15 +113,15 @@ public void testOutputStream(final Map<String, ?> env) throws Exception {
108
113
final byte [] buf = new byte [chunk .length ];
109
114
int numRead ;
110
115
long totalRead = 0 ;
116
+ long start = System .currentTimeMillis ();
111
117
while ((numRead = is .read (buf )) != -1 ) {
112
118
totalRead += numRead ;
113
119
// 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 );
119
122
}
123
+ System .out .println ("Read entry " + entryPath + " of bytes " + totalRead
124
+ + " in " + (System .currentTimeMillis () - start ) + " milli seconds" );
120
125
Assert .assertEquals (totalRead , (long ) entry .getValue (),
121
126
"Unexpected number of bytes read from zip entry " + entryPath );
122
127
}
0 commit comments