test/java/util/zip/LargeZip.java

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

*** 96,118 **** bb.putDouble(0, Math.random()); baos.write(bb.array(), 0, DATA_SIZE); } data = baos.toByteArray(); ! ZipOutputStream zos = new ZipOutputStream( ! new BufferedOutputStream(new FileOutputStream(largeFile))); long length = 0; while (length < fileSize) { ZipEntry ze = new ZipEntry("entry-" + length); lastEntryName = ze.getName(); zos.putNextEntry(ze); zos.write(data, 0, data.length); zos.closeEntry(); length = largeFile.length(); } System.out.println("Last entry written is " + lastEntryName); ! zos.close(); } static void readLargeZip1() throws Throwable { ZipFile zipFile = new ZipFile(largeFile); ZipEntry entry = null; --- 96,120 ---- bb.putDouble(0, Math.random()); baos.write(bb.array(), 0, DATA_SIZE); } data = baos.toByteArray(); ! try (FileOutputStream fos = new FileOutputStream(largeFile); ! BufferedOutputStream bos = new BufferedOutputStream(fos); ! ZipOutputStream zos = new ZipOutputStream(bos)) ! { long length = 0; while (length < fileSize) { ZipEntry ze = new ZipEntry("entry-" + length); lastEntryName = ze.getName(); zos.putNextEntry(ze); zos.write(data, 0, data.length); zos.closeEntry(); length = largeFile.length(); } System.out.println("Last entry written is " + lastEntryName); ! } } static void readLargeZip1() throws Throwable { ZipFile zipFile = new ZipFile(largeFile); ZipEntry entry = null;
*** 141,152 **** } } static void readLargeZip2() throws Throwable { ! ZipInputStream zis = new ZipInputStream( ! new BufferedInputStream(new FileInputStream(largeFile))); ZipEntry entry = null; String entryName = null; int count = 0; while ((entry = zis.getNextEntry()) != null) { entryName = entry.getName(); --- 143,156 ---- } } static void readLargeZip2() throws Throwable { ! try (FileInputStream fis = new FileInputStream(largeFile); ! BufferedInputStream bis = new BufferedInputStream(fis); ! ZipInputStream zis = new ZipInputStream(bis)) ! { ZipEntry entry = null; String entryName = null; int count = 0; while ((entry = zis.getNextEntry()) != null) { entryName = entry.getName();
*** 167,177 **** baos.write(buf, 0, len); } baos.close(); check(Arrays.equals(data, baos.toByteArray())); check(zis.getNextEntry() == null); ! zis.close(); } //--------------------- Infrastructure --------------------------- static volatile int passed = 0, failed = 0; --- 171,181 ---- baos.write(buf, 0, len); } baos.close(); check(Arrays.equals(data, baos.toByteArray())); check(zis.getNextEntry() == null); ! } } //--------------------- Infrastructure --------------------------- static volatile int passed = 0, failed = 0;