test/java/util/zip/ZipFile/LargeZipFile.java
Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX
*** 91,118 ****
for (int i = 0; i < iterations; i++) {
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 readLargeZip() throws Throwable {
! ZipFile zipFile = new ZipFile(largeFile);
ZipEntry entry = null;
String entryName = null;
int count = 0;
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
--- 91,119 ----
for (int i = 0; i < iterations; i++) {
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 readLargeZip() throws Throwable {
! try (ZipFile zipFile = new ZipFile(largeFile)) {
ZipEntry entry = null;
String entryName = null;
int count = 0;
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
*** 133,145 ****
}
baos.close();
is.close();
check(Arrays.equals(data, baos.toByteArray()));
}
! try {
! zipFile.close();
! } catch (IOException ioe) {/* what can you do */ }
}
//--------------------- Infrastructure ---------------------------
static volatile int passed = 0, failed = 0;
static void pass() {passed++;}
--- 134,144 ----
}
baos.close();
is.close();
check(Arrays.equals(data, baos.toByteArray()));
}
! }
}
//--------------------- Infrastructure ---------------------------
static volatile int passed = 0, failed = 0;
static void pass() {passed++;}