Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/demo/zipfs/ReleaseDeflater.java
38833 views
1
/*
2
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
/*
26
* @test
27
* @bug 8234011
28
* @summary Check that jdk.nio.zipfs.ZipFileSystem doesn't cache more than ZipFileSystem.MAX_FLATER Inflater/Deflater objects
29
* @run main ReleaseDeflater
30
* @author Volker Simonis
31
*/
32
33
import java.io.InputStream;
34
import java.io.OutputStream;
35
import java.lang.reflect.Field;
36
import java.net.URI;
37
import java.nio.file.FileSystem;
38
import java.nio.file.FileSystems;
39
import java.nio.file.Files;
40
import java.nio.file.Path;
41
import java.nio.file.Paths;
42
import java.nio.file.spi.FileSystemProvider;
43
import java.util.List;
44
import java.util.Map;
45
import java.util.ArrayList;
46
import java.util.HashMap;
47
48
public class ReleaseDeflater {
49
public static void main(String[] args) throws Throwable {
50
Path zipFile = Paths.get("ReleaseDeflaterTest.zip").toAbsolutePath();
51
URI zipURI = URI.create("jar:" + zipFile.toUri());
52
Map<String, String> env = new HashMap<>();
53
env.put("create", "true");
54
try (FileSystem fs = FileSystems.newFileSystem(zipURI, env)) {
55
FileSystemProvider zprov = fs.provider();
56
Path test = fs.getPath("test.txt");
57
int STREAMS = 100;
58
List<OutputStream> ostreams = new ArrayList<>(STREAMS);
59
List<InputStream> istreams = new ArrayList<>(STREAMS);
60
for (int i = 0; i < STREAMS; i++) {
61
OutputStream zos = zprov.newOutputStream(test);
62
ostreams.add(zos);
63
zos.write("Hello".getBytes());
64
}
65
for (OutputStream os : ostreams) {
66
os.close();
67
}
68
for (int i = 0; i < STREAMS; i++) {
69
InputStream zis = zprov.newInputStream(test);
70
istreams.add(zis);
71
}
72
for (InputStream is : istreams) {
73
is.close();
74
}
75
try {
76
Field max_flaters = fs.getClass().getDeclaredField("MAX_FLATER");
77
max_flaters.setAccessible(true);
78
int MAX_FLATERS = max_flaters.getInt(fs);
79
Field inflaters = fs.getClass().getDeclaredField("inflaters");
80
inflaters.setAccessible(true);
81
int inflater_count = ((List<?>) inflaters.get(fs)).size();
82
if (inflater_count > MAX_FLATERS) {
83
throw new Exception("Too many inflaters " + inflater_count);
84
}
85
Field deflaters = fs.getClass().getDeclaredField("deflaters");
86
deflaters.setAccessible(true);
87
int deflater_count = ((List<?>) deflaters.get(fs)).size();
88
if (deflater_count > MAX_FLATERS) {
89
throw new Exception("Too many deflaters " + deflater_count);
90
}
91
} catch (NoSuchFieldException nsfe) {
92
// Probably the implementation has changed, so there's not much we can do...
93
throw new RuntimeException("Implementation of jdk.nio.zipfs.ZipFileSystem changed - disable or fix the test");
94
}
95
} finally {
96
Files.deleteIfExists(zipFile);
97
}
98
99
}
100
}
101
102