Cleanup (I/O ops in java-decompiler)
This commit is contained in:
@@ -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.
|
||||
@@ -150,17 +150,11 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver {
|
||||
return InterpreterUtil.getBytes(file);
|
||||
}
|
||||
else {
|
||||
ZipFile archive = new ZipFile(file);
|
||||
try {
|
||||
try (ZipFile archive = new ZipFile(file)) {
|
||||
ZipEntry entry = archive.getEntry(internalPath);
|
||||
if (entry == null) {
|
||||
throw new IOException("Entry not found: " + internalPath);
|
||||
}
|
||||
if (entry == null) throw new IOException("Entry not found: " + internalPath);
|
||||
return InterpreterUtil.getBytes(archive, entry);
|
||||
}
|
||||
finally {
|
||||
archive.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,14 +187,8 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver {
|
||||
@Override
|
||||
public void saveClassFile(String path, String qualifiedName, String entryName, String content, int[] mapping) {
|
||||
File file = new File(getAbsolutePath(path), entryName);
|
||||
try {
|
||||
Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF8");
|
||||
try {
|
||||
out.write(content);
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
try (Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF8")) {
|
||||
out.write(content);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
DecompilerContext.getLogger().writeMessage("Cannot write class file " + file, ex);
|
||||
@@ -238,21 +226,15 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ZipFile srcArchive = new ZipFile(new File(source));
|
||||
try {
|
||||
ZipEntry entry = srcArchive.getEntry(entryName);
|
||||
if (entry != null) {
|
||||
InputStream in = srcArchive.getInputStream(entry);
|
||||
try (ZipFile srcArchive = new ZipFile(new File(source))) {
|
||||
ZipEntry entry = srcArchive.getEntry(entryName);
|
||||
if (entry != null) {
|
||||
try (InputStream in = srcArchive.getInputStream(entry)) {
|
||||
ZipOutputStream out = mapArchiveStreams.get(file);
|
||||
out.putNextEntry(new ZipEntry(entryName));
|
||||
InterpreterUtil.copyStream(in, out);
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
srcArchive.close();
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
String message = "Cannot copy entry " + entryName + " from " + source + " to " + file;
|
||||
@@ -306,4 +288,4 @@ public class ConsoleDecompiler implements IBytecodeProvider, IResultSaver {
|
||||
DecompilerContext.getLogger().writeMessage("Cannot close " + file, IFernflowerLogger.Severity.WARN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user