4294N/A/*
4294N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4294N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4294N/A *
4294N/A * This code is free software; you can redistribute it and/or modify it
4294N/A * under the terms of the GNU General Public License version 2 only, as
4294N/A * published by the Free Software Foundation.
4294N/A *
4294N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4294N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4294N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4294N/A * version 2 for more details (a copy is included in the LICENSE file that
4294N/A * accompanied this code).
4294N/A *
4294N/A * You should have received a copy of the GNU General Public License version
4294N/A * 2 along with this work; if not, write to the Free Software Foundation,
4294N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4294N/A *
4294N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4294N/A * or visit www.oracle.com if you need additional information or have any
4294N/A * questions.
4294N/A */
4294N/A
4294N/Aimport java.io.File;
4294N/Aimport java.io.FileOutputStream;
4294N/Aimport java.io.InputStream;
4294N/Aimport java.io.OutputStream;
4294N/Aimport java.net.URL;
4294N/Aimport java.net.URLClassLoader;
4294N/Aimport java.net.URLConnection;
4294N/Aimport java.util.zip.CRC32;
4294N/Aimport java.util.zip.ZipEntry;
4294N/Aimport java.util.zip.ZipOutputStream;
4294N/A
4294N/A/**
4294N/A * @test
4294N/A * @bug 7050028
4294N/A * @summary ISE "zip file closed" from JarURLConnection.getInputStream on JDK 7 when !useCaches
4294N/A * @run main/othervm B7050028
4294N/A */
4294N/A
4294N/Apublic class B7050028 {
4294N/A public static void main(String[] args) throws Exception {
4294N/A URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection();
4294N/A int len = conn.getContentLength();
4294N/A byte[] data = new byte[len];
4294N/A InputStream is = conn.getInputStream();
4294N/A is.read(data);
4294N/A is.close();
4294N/A conn.setDefaultUseCaches(false);
4294N/A File jar = File.createTempFile("B7050028", ".jar");
4294N/A jar.deleteOnExit();
4294N/A OutputStream os = new FileOutputStream(jar);
4294N/A ZipOutputStream zos = new ZipOutputStream(os);
4294N/A ZipEntry ze = new ZipEntry("B7050028.class");
4294N/A ze.setMethod(ZipEntry.STORED);
4294N/A ze.setSize(len);
4294N/A CRC32 crc = new CRC32();
4294N/A crc.update(data);
4294N/A ze.setCrc(crc.getValue());
4294N/A zos.putNextEntry(ze);
4294N/A zos.write(data, 0, len);
4294N/A zos.closeEntry();
4294N/A zos.finish();
4294N/A zos.close();
4294N/A os.close();
4294N/A System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName()));
4294N/A }
4294N/A private B7050028() {}
4294N/A}