test/java/util/zip/zip.java
Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX
*** 320,343 ****
}
}
void create(OutputStream out) throws IOException
{
! ZipOutputStream zos = new ZipOutputStream(out, cs);
if (flag0) {
zos.setMethod(ZipOutputStream.STORED);
}
for (File file: entries) {
addFile(zos, file);
}
! zos.close();
}
boolean update(InputStream in, OutputStream out) throws IOException
{
! ZipInputStream zis = new ZipInputStream(in, cs);
! ZipOutputStream zos = new ZipOutputStream(out, cs);
ZipEntry e = null;
byte[] buf = new byte[1024];
int n = 0;
boolean updateOk = true;
--- 320,344 ----
}
}
void create(OutputStream out) throws IOException
{
! try (ZipOutputStream zos = new ZipOutputStream(out, cs)) {
if (flag0) {
zos.setMethod(ZipOutputStream.STORED);
}
for (File file: entries) {
addFile(zos, file);
}
! }
}
boolean update(InputStream in, OutputStream out) throws IOException
{
! try (ZipInputStream zis = new ZipInputStream(in, cs);
! ZipOutputStream zos = new ZipOutputStream(out, cs))
! {
ZipEntry e = null;
byte[] buf = new byte[1024];
int n = 0;
boolean updateOk = true;
*** 369,380 ****
// add the remaining new files
for (File f: entries) {
addFile(zos, f);
}
! zis.close();
! zos.close();
return updateOk;
}
private String entryName(String name) {
name = name.replace(File.separatorChar, '/');
--- 370,380 ----
// add the remaining new files
for (File f: entries) {
addFile(zos, f);
}
! }
return updateOk;
}
private String entryName(String name) {
name = name.replace(File.separatorChar, '/');
*** 515,525 ****
}
updateLastModifiedTime(dirs);
}
void extract(String fname, String files[]) throws IOException {
! ZipFile zf = new ZipFile(fname, cs);
Set<ZipEntry> dirs = newDirSet();
Enumeration<? extends ZipEntry> zes = zf.entries();
while (zes.hasMoreElements()) {
ZipEntry e = zes.nextElement();
InputStream is;
--- 515,525 ----
}
updateLastModifiedTime(dirs);
}
void extract(String fname, String files[]) throws IOException {
! try (ZipFile zf = new ZipFile(fname, cs)) {
Set<ZipEntry> dirs = newDirSet();
Enumeration<? extends ZipEntry> zes = zf.entries();
while (zes.hasMoreElements()) {
ZipEntry e = zes.nextElement();
InputStream is;
*** 533,543 ****
break;
}
}
}
}
! zf.close();
updateLastModifiedTime(dirs);
}
ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException {
ZipEntry rc = null;
--- 533,543 ----
break;
}
}
}
}
! }
updateLastModifiedTime(dirs);
}
ZipEntry extractFile(InputStream is, ZipEntry e) throws IOException {
ZipEntry rc = null;
*** 605,620 ****
printEntry(e, files);
}
}
void list(String fname, String files[]) throws IOException {
! ZipFile zf = new ZipFile(fname, cs);
Enumeration<? extends ZipEntry> zes = zf.entries();
while (zes.hasMoreElements()) {
printEntry(zes.nextElement(), files);
}
! zf.close();
}
void printEntry(ZipEntry e, String[] files) throws IOException {
if (files == null) {
printEntry(e);
--- 605,620 ----
printEntry(e, files);
}
}
void list(String fname, String files[]) throws IOException {
! try (ZipFile zf = new ZipFile(fname, cs)) {
Enumeration<? extends ZipEntry> zes = zf.entries();
while (zes.hasMoreElements()) {
printEntry(zes.nextElement(), files);
}
! }
}
void printEntry(ZipEntry e, String[] files) throws IOException {
if (files == null) {
printEntry(e);