src/share/classes/java/util/jar/JarFile.java

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

*** 374,386 **** * Reads all the bytes for a given entry. Used to process the * META-INF files. */ private byte[] getBytes(ZipEntry ze) throws IOException { byte[] b = new byte[(int)ze.getSize()]; ! DataInputStream is = new DataInputStream(super.getInputStream(ze)); is.readFully(b, 0, b.length); ! is.close(); return b; } /** * Returns an input stream for reading the contents of the specified --- 374,386 ---- * Reads all the bytes for a given entry. Used to process the * META-INF files. */ private byte[] getBytes(ZipEntry ze) throws IOException { byte[] b = new byte[(int)ze.getSize()]; ! try (DataInputStream is = new DataInputStream(super.getInputStream(ze))) { is.readFully(b, 0, b.length); ! } return b; } /** * Returns an input stream for reading the contents of the specified
*** 478,491 **** hasClassPathAttribute = false; if (!isKnownToNotHaveClassPathAttribute()) { JarEntry manEntry = getManEntry(); if (manEntry != null) { byte[] b = new byte[(int)manEntry.getSize()]; ! DataInputStream dis = new DataInputStream( ! super.getInputStream(manEntry)); dis.readFully(b, 0, b.length); ! dis.close(); int last = b.length - src.length; int i = 0; next: while (i<=last) { --- 478,491 ---- hasClassPathAttribute = false; if (!isKnownToNotHaveClassPathAttribute()) { JarEntry manEntry = getManEntry(); if (manEntry != null) { byte[] b = new byte[(int)manEntry.getSize()]; ! try (DataInputStream dis = new DataInputStream( ! super.getInputStream(manEntry))) { dis.readFully(b, 0, b.length); ! } int last = b.length - src.length; int i = 0; next: while (i<=last) {