author | jjg |
Wed, 04 Jan 2017 18:33:20 -0800 | |
changeset 43029 | 1cd1c816581e |
parent 9823 | 2bc6b0d4490e |
permissions | -rw-r--r-- |
9823
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
1 |
/* |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
2 |
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
4 |
* |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
8 |
* |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
14 |
* |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
18 |
* |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
21 |
* questions. |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
22 |
*/ |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
23 |
|
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
24 |
import java.io.File; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
25 |
import java.io.FileOutputStream; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
26 |
import java.io.InputStream; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
27 |
import java.io.OutputStream; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
28 |
import java.net.URL; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
29 |
import java.net.URLClassLoader; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
30 |
import java.net.URLConnection; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
31 |
import java.util.zip.CRC32; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
32 |
import java.util.zip.ZipEntry; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
33 |
import java.util.zip.ZipOutputStream; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
34 |
|
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
35 |
/** |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
36 |
* @test |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
37 |
* @bug 7050028 |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
38 |
* @summary ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
39 |
* @run main/othervm B7050028 |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
40 |
*/ |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
41 |
|
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
42 |
public class B7050028 { |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws Exception { |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
44 |
URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
45 |
int len = conn.getContentLength(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
46 |
byte[] data = new byte[len]; |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
47 |
InputStream is = conn.getInputStream(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
48 |
is.read(data); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
49 |
is.close(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
50 |
conn.setDefaultUseCaches(false); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
51 |
File jar = File.createTempFile("B7050028", ".jar"); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
52 |
jar.deleteOnExit(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
53 |
OutputStream os = new FileOutputStream(jar); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
54 |
ZipOutputStream zos = new ZipOutputStream(os); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
55 |
ZipEntry ze = new ZipEntry("B7050028.class"); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
56 |
ze.setMethod(ZipEntry.STORED); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
57 |
ze.setSize(len); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
58 |
CRC32 crc = new CRC32(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
59 |
crc.update(data); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
60 |
ze.setCrc(crc.getValue()); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
61 |
zos.putNextEntry(ze); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
62 |
zos.write(data, 0, len); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
63 |
zos.closeEntry(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
64 |
zos.finish(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
65 |
zos.close(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
66 |
os.close(); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
67 |
System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
68 |
} |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
69 |
private B7050028() {} |
2bc6b0d4490e
7050028: ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
michaelm
parents:
diff
changeset
|
70 |
} |