/*
* Copyright ( c ) 2011 , Oracle and / or its affiliates . All rights reserved .
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER .
*
* This code is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License version 2 only , as
* published by the Free Software Foundation .
*
* This code is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE . See the GNU General Public License
* version 2 for more details ( a copy is included in the LICENSE file that
* accompanied this code ) .
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work ; if not , write to the Free Software Foundation ,
* Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA .
*
* Please contact Oracle , 500 Oracle Parkway , Redwood Shores , CA 94065 USA
* or visit www . oracle . com if you need additional information or have any
* questions .
*/
/**
* @ test
* @ bug 6896088
* @ run main / othervm B6896088
* @ summary URLClassLoader . close ( ) apparently not working for JAR URLs on Windows
*/
import java.net.*;
import java.io.*;
import java.nio.file.Path;
public class B6896088 {
public static void main(String[] args) throws Exception {
String dir = System.getProperty ("test.classes" );
File jarf = new File (dir, "foo.jar" );
FileOutputStream fos = new FileOutputStream (jarf);
fos.write(bytes(nums));
fos.close();
// Create URL using JAR protocol
String jarName = (jarf.toURI()).toString();
URL url = new URL("jar" , "" , jarName + "!/" );
// Create URLClassLoader from the URL
URLClassLoader loader = new URLClassLoader(new URL[]{url});
Class c = loader.loadClass("Foo" );
// Close the URLClassLoader so we can delete/update the jar file
loader.close();
// Now try to delete the jar file
if (jarf.delete () && !jarf.exists()) {
System.out.println(jarf.getName()+" File Deleted" );
} else {
System.out.println(jarf.getName()+" File Not Deleted" );
throw new RuntimeException ("File not deleted" );
}
}
static byte [] bytes (int [] i) {
byte [] buf = new byte [i.length];
for (int j=0 ; j<i.length; j++) {
buf[j] = (byte )i[j];
}
return buf;
}
/* contents of foo.jar */
static final int nums[] = {
0 x50,0 x4b,0 x03,0 x04,0 x14,0 x00,0 x08,0 x08,0 x08,0 x00,0 xc8,0 x61,
0 x90,0 x3d,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,
0 x00,0 x00,0 x09,0 x00,0 x04,0 x00,0 x4d,0 x45,0 x54,0 x41,0 x2d,0 x49,
0 x4e,0 x46,0 x2f,0 xfe,0 xca,0 x00,0 x00,0 x03,0 x00,0 x50,0 x4b,0 x07,
0 x08,0 x00,0 x00,0 x00,0 x00,0 x02,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,
0 x00,0 x50,0 x4b,0 x03,0 x04,0 x14,0 x00,0 x08,0 x08,0 x08,0 x00,0 xc8,
0 x61,0 x90,0 x3d,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,
0 x00,0 x00,0 x00,0 x14,0 x00,0 x00,0 x00,0 x4d,0 x45,0 x54,0 x41,0 x2d,
0 x49,0 x4e,0 x46,0 x2f,0 x4d,0 x41,0 x4e,0 x49,0 x46,0 x45,0 x53,0 x54,
0 x2e,0 x4d,0 x46,0 xf3,0 x4d,0 xcc,0 xcb,0 x4c,0 x4b,0 x2d,0 x2e,0 xd1,
0 x0d,0 x4b,0 x2d,0 x2a,0 xce,0 xcc,0 xcf,0 xb3,0 x52,0 x30,0 xd4,0 x33,
0 xe0,0 xe5,0 x72,0 x2e,0 x4a,0 x4d,0 x2c,0 x49,0 x4d,0 xd1,0 x75,0 xaa,
0 x04,0 x09,0 x98,0 xeb,0 x19,0 xe8,0 x66,0 xe6,0 x95,0 xa4,0 x16,0 xe5,
0 x25,0 xe6,0 x28,0 x68,0 xf8,0 x17,0 x25,0 x26,0 xe7,0 xa4,0 x2a,0 x38,
0 xe7,0 x17,0 x15,0 xe4,0 x17,0 x25,0 x96,0 x00,0 x35,0 x69,0 xf2,0 x72,
0 xf1,0 x72,0 x01,0 x00,0 x50,0 x4b,0 x07,0 x08,0 x4c,0 xd8,0 x5e,0 x68,
0 x49,0 x00,0 x00,0 x00,0 x4a,0 x00,0 x00,0 x00,0 x50,0 x4b,0 x03,0 x04,
0 x14,0 x00,0 x08,0 x08,0 x08,0 x00,0 xbd,0 x61,0 x90,0 x3d,0 x00,0 x00,
0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x09,0 x00,
0 x00,0 x00,0 x46,0 x6f,0 x6f,0 x2e,0 x63,0 x6c,0 x61,0 x73,0 x73,0 x3b,
0 xf5,0 x6f,0 xd7,0 x3e,0 x06,0 x06,0 x06,0 x63,0 x06,0 x5e,0 x2e,0 x06,
0 x66,0 x06,0 x2e,0 x76,0 x06,0 x6e,0 x76,0 x06,0 x1e,0 x46,0 x06,0 x36,
0 x9b,0 xcc,0 xbc,0 xcc,0 x12,0 x3b,0 x46,0 x06,0 x66,0 x0d,0 xcd,0 x30,
0 x46,0 x06,0 x16,0 xe7,0 xfc,0 x94,0 x54,0 x46,0 x06,0 x7e,0 x9f,0 xcc,
0 xbc,0 x54,0 xbf,0 xd2,0 xdc,0 xa4,0 xd4,0 xa2,0 x90,0 xc4,0 xa4,0 x1c,
0 xa0,0 x08,0 x57,0 x70,0 x7e,0 x69,0 x51,0 x72,0 xaa,0 x5b,0 x26,0 x88,
0 xc3,0 xe1,0 x96,0 x9f,0 xaf,0 x97,0 x95,0 x58,0 x96,0 xc8,0 xc3,0 xc0,
0 xc2,0 xc0,0 x0a,0 xd4,0 x0b,0 xe4,0 x33,0 x32,0 x08,0 x80,0 x44,0 xf4,
0 x73,0 x12,0 xf3,0 xd2,0 xf5,0 xfd,0 x93,0 xb2,0 x52,0 x93,0 x4b,0 x18,
0 x14,0 x19,0 x98,0 x80,0 x76,0 x81,0 x00,0 x23,0 x10,0 x02,0 x95,0 x02,
0 x49,0 x36,0 x20,0 x4f,0 x16,0 xcc,0 x67,0 x60,0 x60,0 xd5,0 xda,0 xce,
0 xc0,0 xb8,0 x11,0 x2c,0 xcd,0 x0e,0 x24,0 xd9,0 xc0,0 x82,0 x20,0 x29,
0 x0e,0 x20,0 xcd,0 xc4,0 xc0,0 x09,0 x00,0 x50,0 x4b,0 x07,0 x08,0 x3e,
0 x0a,0 xdc,0 x88,0 x98,0 x00,0 x00,0 x00,0 xb4,0 x00,0 x00,0 x00,0 x50,
0 x4b,0 x01,0 x02,0 x14,0 x00,0 x14,0 x00,0 x08,0 x08,0 x08,0 x00,0 xc8,
0 x61,0 x90,0 x3d,0 x00,0 x00,0 x00,0 x00,0 x02,0 x00,0 x00,0 x00,0 x00,
0 x00,0 x00,0 x00,0 x09,0 x00,0 x04,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,
0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x4d,0 x45,0 x54,
0 x41,0 x2d,0 x49,0 x4e,0 x46,0 x2f,0 xfe,0 xca,0 x00,0 x00,0 x50,0 x4b,
0 x01,0 x02,0 x14,0 x00,0 x14,0 x00,0 x08,0 x08,0 x08,0 x00,0 xc8,0 x61,
0 x90,0 x3d,0 x4c,0 xd8,0 x5e,0 x68,0 x49,0 x00,0 x00,0 x00,0 x4a,0 x00,
0 x00,0 x00,0 x14,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,
0 x00,0 x00,0 x00,0 x00,0 x3d,0 x00,0 x00,0 x00,0 x4d,0 x45,0 x54,0 x41,
0 x2d,0 x49,0 x4e,0 x46,0 x2f,0 x4d,0 x41,0 x4e,0 x49,0 x46,0 x45,0 x53,
0 x54,0 x2e,0 x4d,0 x46,0 x50,0 x4b,0 x01,0 x02,0 x14,0 x00,0 x14,0 x00,
0 x08,0 x08,0 x08,0 x00,0 xbd,0 x61,0 x90,0 x3d,0 x3e,0 x0a,0 xdc,0 x88,
0 x98,0 x00,0 x00,0 x00,0 xb4,0 x00,0 x00,0 x00,0 x09,0 x00,0 x00,0 x00,
0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 x00,0 xc8,0 x00,
0 x00,0 x00,0 x46,0 x6f,0 x6f,0 x2e,0 x63,0 x6c,0 x61,0 x73,0 x73,0 x50,
0 x4b,0 x05,0 x06,0 x00,0 x00,0 x00,0 x00,0 x03,0 x00,0 x03,0 x00,0 xb4,
0 x00,0 x00,0 x00,0 x97,0 x01,0 x00,0 x00,0 x00,0 x00,0 x00
};
}
Messung V0.5 in Prozent C=95 H=88 G=91