Merge pull request #143 from DevFactory/release/resource-should-be-closed-fix-1

[squid:S2095] Resources should be closed
This commit is contained in:
Kalen (Konloch) Kinloch 2016-06-17 14:55:11 -06:00 committed by GitHub
commit a80da1ed98
3 changed files with 10 additions and 20 deletions

View file

@ -192,9 +192,9 @@ public class JarUtils {
*/ */
public static void saveAsJar(ArrayList<ClassNode> nodeList, String path, public static void saveAsJar(ArrayList<ClassNode> nodeList, String path,
String manifest) { String manifest) {
try { try (JarOutputStream out = new JarOutputStream(
JarOutputStream out = new JarOutputStream( new FileOutputStream(path))) {
new FileOutputStream(path));
for (ClassNode cn : nodeList) { for (ClassNode cn : nodeList) {
ClassWriter cw = new ClassWriter(0); ClassWriter cw = new ClassWriter(0);
cn.accept(cw); cn.accept(cw);
@ -218,7 +218,6 @@ public class JarUtils {
} }
} }
out.close();
} catch (IOException e) { } catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
@ -230,8 +229,7 @@ public class JarUtils {
* @param path the exact jar output path * @param path the exact jar output path
*/ */
public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String path) { public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String path) {
try { try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
JarOutputStream out = new JarOutputStream(new FileOutputStream(path));
ArrayList<String> noDupe = new ArrayList<String>(); ArrayList<String> noDupe = new ArrayList<String>();
for (ClassNode cn : nodeList) { for (ClassNode cn : nodeList) {
ClassWriter cw = new ClassWriter(0); ClassWriter cw = new ClassWriter(0);
@ -248,15 +246,13 @@ public class JarUtils {
} }
noDupe.clear(); noDupe.clear();
out.close();
} catch (IOException e) { } catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
} }
public static void saveAsJarClassesOnly(Map<String, byte[]> nodeList, String path) { public static void saveAsJarClassesOnly(Map<String, byte[]> nodeList, String path) {
try { try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
JarOutputStream out = new JarOutputStream(new FileOutputStream(path));
ArrayList<String> noDupe = new ArrayList<String>(); ArrayList<String> noDupe = new ArrayList<String>();
for (Entry<String, byte[]> cn : nodeList.entrySet()) { for (Entry<String, byte[]> cn : nodeList.entrySet()) {
String name = cn.getKey(); String name = cn.getKey();
@ -269,15 +265,13 @@ public class JarUtils {
} }
noDupe.clear(); noDupe.clear();
out.close();
} catch (IOException e) { } catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }
} }
public static void saveAsJar(Map<String, byte[]> nodeList, String path) { public static void saveAsJar(Map<String, byte[]> nodeList, String path) {
try { try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
JarOutputStream out = new JarOutputStream(new FileOutputStream(path));
ArrayList<String> noDupe = new ArrayList<String>(); ArrayList<String> noDupe = new ArrayList<String>();
for (Entry<String, byte[]> entry : nodeList.entrySet()) { for (Entry<String, byte[]> entry : nodeList.entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
@ -303,7 +297,6 @@ public class JarUtils {
} }
noDupe.clear(); noDupe.clear();
out.close();
} catch (IOException e) { } catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }

View file

@ -60,9 +60,9 @@ public class JDGUIDecompiler extends Decompiler {
@Override @Override
public void decompileToZip(String zipName) { public void decompileToZip(String zipName) {
try { File output = new File(zipName);
File output = new File(zipName); try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(output))) {
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(output));
for (Map.Entry<String, byte[]> entry : BytecodeViewer.getLoadedBytes().entrySet()) { for (Map.Entry<String, byte[]> entry : BytecodeViewer.getLoadedBytes().entrySet()) {
String name = entry.getKey(); String name = entry.getKey();
if (name.endsWith(".class")) { if (name.endsWith(".class")) {
@ -82,7 +82,6 @@ public class JDGUIDecompiler extends Decompiler {
} }
zipOutputStream.closeEntry(); zipOutputStream.closeEntry();
} }
zipOutputStream.close();
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
} }

View file

@ -291,13 +291,11 @@ public class InstructionPrinter {
} }
public static void saveTo(File file, InstructionPrinter printer) { public static void saveTo(File file, InstructionPrinter printer) {
try { try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
for (String s : printer.createPrint()) { for (String s : printer.createPrint()) {
bw.write(s); bw.write(s);
bw.newLine(); bw.newLine();
} }
bw.close();
} catch (IOException e) { } catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e); new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
} }