test/java/util/jar/JarEntry/GetMethodsReturnClones.java

Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: alanb, dholmes, sherman

*** 38,63 **** private final static String BASE = System.getProperty("test.src", ".") + System.getProperty("file.separator"); public static void main(String[] args) throws Exception { ! JarFile jf = new JarFile(BASE + "test.jar", true); ! byte[] buffer = new byte[8192]; Enumeration<JarEntry> e = jf.entries(); - List<JarEntry> entries = new ArrayList<JarEntry>(); while (e.hasMoreElements()) { JarEntry je = e.nextElement(); entries.add(je); ! InputStream is = jf.getInputStream(je); while (is.read(buffer, 0, buffer.length) != -1) { // we just read. this will throw a SecurityException // if a signature/digest check fails. } - is.close(); } ! jf.close(); for (JarEntry je : entries) { Certificate[] certs = je.getCertificates(); CodeSigner[] signers = je.getCodeSigners(); if (certs != null) { --- 38,62 ---- private final static String BASE = System.getProperty("test.src", ".") + System.getProperty("file.separator"); public static void main(String[] args) throws Exception { ! List<JarEntry> entries = new ArrayList<>(); ! try (JarFile jf = new JarFile(BASE + "test.jar", true)) { byte[] buffer = new byte[8192]; Enumeration<JarEntry> e = jf.entries(); while (e.hasMoreElements()) { JarEntry je = e.nextElement(); entries.add(je); ! try (InputStream is = jf.getInputStream(je)) { while (is.read(buffer, 0, buffer.length) != -1) { // we just read. this will throw a SecurityException // if a signature/digest check fails. } } ! } ! } for (JarEntry je : entries) { Certificate[] certs = je.getCertificates(); CodeSigner[] signers = je.getCodeSigners(); if (certs != null) {