Cleanup (I/O ops in java-decompiler)

This commit is contained in:
Roman Shevchenko
2016-03-16 11:22:21 +01:00
parent 5795c1d9e0
commit 23da5d99d2
8 changed files with 78 additions and 161 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,26 +69,18 @@ public class BulkDecompilationTest {
}
private static void unpack(File archive, File targetDir) {
try {
ZipFile zip = new ZipFile(archive);
try {
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
File file = new File(targetDir, entry.getName());
assertTrue(file.getParentFile().mkdirs() || file.getParentFile().isDirectory());
InputStream in = zip.getInputStream(entry);
OutputStream out = new FileOutputStream(file);
try (ZipFile zip = new ZipFile(archive)) {
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
File file = new File(targetDir, entry.getName());
assertTrue(file.getParentFile().mkdirs() || file.getParentFile().isDirectory());
try (InputStream in = zip.getInputStream(entry); OutputStream out = new FileOutputStream(file)) {
InterpreterUtil.copyStream(in, out);
out.close();
in.close();
}
}
}
finally {
zip.close();
}
}
catch (IOException e) {
throw new RuntimeException(e);