< prev index next >
test/hotspot/jtreg/runtime/appcds/test-classes/Util.java
Print this page
*** 37,47 ****
*/
public static Class defineModifiedClass(ClassLoader loader, File clsFile, String fromString, String toString)
throws FileNotFoundException, IOException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException
{
! DataInputStream dis = new DataInputStream(new FileInputStream(clsFile));
byte[] buff = new byte[(int)clsFile.length()];
dis.readFully(buff);
replace(buff, fromString, toString);
System.out.println("Loading from: " + clsFile + " (" + buff.length + " bytes)");
--- 37,47 ----
*/
public static Class defineModifiedClass(ClassLoader loader, File clsFile, String fromString, String toString)
throws FileNotFoundException, IOException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException
{
! try (DataInputStream dis = new DataInputStream(new FileInputStream(clsFile))) {
byte[] buff = new byte[(int)clsFile.length()];
dis.readFully(buff);
replace(buff, fromString, toString);
System.out.println("Loading from: " + clsFile + " (" + buff.length + " bytes)");
*** 56,65 ****
--- 56,66 ----
Class cls = (Class)defineClass.invoke(loader, buff, new Integer(0), new Integer(buff.length));
System.out.println("Loaded : " + cls);
return cls;
}
+ }
/**
* @return the number of occurrences of the <code>from</code> string that
* have been replaced.
*/
*** 144,156 ****
public static byte[] getClassFileFromJar(File jarFile, String className) throws FileNotFoundException, IOException {
JarFile jf = new JarFile(jarFile);
JarEntry ent = jf.getJarEntry(className.replace('.', '/') + ".class");
! DataInputStream dis = new DataInputStream(jf.getInputStream(ent));
byte[] buff = new byte[(int)ent.getSize()];
dis.readFully(buff);
- dis.close();
-
return buff;
}
}
--- 145,156 ----
public static byte[] getClassFileFromJar(File jarFile, String className) throws FileNotFoundException, IOException {
JarFile jf = new JarFile(jarFile);
JarEntry ent = jf.getJarEntry(className.replace('.', '/') + ".class");
! try (DataInputStream dis = new DataInputStream(jf.getInputStream(ent))) {
byte[] buff = new byte[(int)ent.getSize()];
dis.readFully(buff);
return buff;
}
+ }
}
< prev index next >