Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/URLClassLoader/B7050028.java
41152 views
1
/*
2
* Copyright (c) 2011, 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
import java.io.File;
25
import java.io.FileOutputStream;
26
import java.io.InputStream;
27
import java.io.OutputStream;
28
import java.net.URL;
29
import java.net.URLClassLoader;
30
import java.net.URLConnection;
31
import java.util.zip.CRC32;
32
import java.util.zip.ZipEntry;
33
import java.util.zip.ZipOutputStream;
34
35
/**
36
* @test
37
* @bug 7050028
38
* @summary ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
39
* @run main/othervm B7050028
40
*/
41
42
public class B7050028 {
43
public static void main(String[] args) throws Exception {
44
URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
45
int len = conn.getContentLength();
46
byte[] data = new byte[len];
47
InputStream is = conn.getInputStream();
48
is.read(data);
49
is.close();
50
conn.setDefaultUseCaches(false);
51
File jar = File.createTempFile("B7050028", ".jar");
52
jar.deleteOnExit();
53
OutputStream os = new FileOutputStream(jar);
54
ZipOutputStream zos = new ZipOutputStream(os);
55
ZipEntry ze = new ZipEntry("B7050028.class");
56
ze.setMethod(ZipEntry.STORED);
57
ze.setSize(len);
58
CRC32 crc = new CRC32();
59
crc.update(data);
60
ze.setCrc(crc.getValue());
61
zos.putNextEntry(ze);
62
zos.write(data, 0, len);
63
zos.closeEntry();
64
zos.finish();
65
zos.close();
66
os.close();
67
System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
68
}
69
private B7050028() {}
70
}
71
72