< prev index next >
test/hotspot/jtreg/runtime/appcds/test-classes/Util.java
Print this page
@@ -37,11 +37,11 @@
*/
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));
+ 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,10 +56,11 @@
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,13 +145,12 @@
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));
+ try (DataInputStream dis = new DataInputStream(jf.getInputStream(ent))) {
byte[] buff = new byte[(int)ent.getSize()];
dis.readFully(buff);
- dis.close();
-
return buff;
}
+ }
}
< prev index next >