Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/tools/jarsigner/LargeJarEntry.java
38853 views
1
/*
2
* Copyright (c) 2006, 2012, Oracle and/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
* @test
26
* @bug 6405538 6474350
27
* @summary Make sure jar files with large entries (more than max heap size)
28
* can be signed
29
* @run main/othervm -Xmx8M LargeJarEntry
30
* @author Sean Mullan
31
*/
32
33
import java.io.File;
34
import java.io.FileOutputStream;
35
import java.util.jar.JarEntry;
36
import java.util.jar.JarOutputStream;
37
import java.util.zip.CRC32;
38
39
public class LargeJarEntry {
40
41
public static void main(String[] args) throws Exception {
42
43
String srcDir = System.getProperty("test.src", ".");
44
String keystore = srcDir + "/JarSigning.keystore";
45
String jarName = "largeJarEntry.jar";
46
47
// Set java.io.tmpdir to the current working dir (see 6474350)
48
System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));
49
50
// first, create jar file with 8M uncompressed entry
51
// note, we set the max heap size to 8M in @run tag above
52
byte[] bytes = new byte[1000000];
53
CRC32 crc = new CRC32();
54
for (int i=0; i<8; i++) {
55
crc.update(bytes);
56
}
57
JarEntry je = new JarEntry("large");
58
je.setSize(8000000l);
59
je.setMethod(JarEntry.STORED);
60
je.setCrc(crc.getValue());
61
File file = new File(jarName);
62
FileOutputStream os = new FileOutputStream(file);
63
JarOutputStream jos = new JarOutputStream(os);
64
jos.setMethod(JarEntry.STORED);
65
jos.putNextEntry(je);
66
for (int i=0; i<8; i++) {
67
jos.write(bytes, 0, bytes.length);
68
}
69
jos.close();
70
71
String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
72
jarName, "b" };
73
// now, try to sign it
74
try {
75
sun.security.tools.jarsigner.Main.main(jsArgs);
76
} catch (OutOfMemoryError err) {
77
throw new Exception("Test failed with OutOfMemoryError", err);
78
} finally {
79
// remove jar file
80
file.delete();
81
}
82
}
83
}
84
85