diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 7b54b38bf..b29566dcb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -1815,7 +1815,9 @@ public final class SWF implements SWFContainerItem, Timelined { @Override public void run() throws IOException { File f = new File(foutdir + File.separator + (fframes.get(fi) + 1) + ".png"); - ImageHelper.write(frameImages.next(), "PNG", new FileOutputStream(f)); + try (FileOutputStream fos = new FileOutputStream(f)) { + ImageHelper.write(frameImages.next(), "PNG", fos); + } ret.add(f); } }, handler).run(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java index 40ce4c40c..12062e315 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScriptParser.java @@ -2350,7 +2350,9 @@ public class ActionScriptParser { ABC abc = new ABC(swf); ActionScriptParser parser = new ActionScriptParser(abc, playerABCs); parser.addScript(new String(Helper.readFile(src), "UTF-8"), true, src, classPos); - abc.saveToStream(new FileOutputStream(new File(dst))); + try (FileOutputStream fos = new FileOutputStream(new File(dst))) { + abc.saveToStream(fos); + } } catch (Exception ex) { Logger.getLogger(ActionScriptParser.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java index 9532ae4fc..8c6eae198 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java @@ -1,18 +1,19 @@ /* * Copyright (C) 2010-2015 JPEXS, All rights reserved. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.exporters; import com.jpexs.decompiler.flash.AbortRetryIgnoreHandler; @@ -77,7 +78,9 @@ public class ImageExporter { if (ffileFormat.equals("bmp")) { BMPFile.saveBitmap(imageTag.getImage().getBufferedImage(), file); } else { - ImageHelper.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), new FileOutputStream(file)); + try (FileOutputStream fos = new FileOutputStream(file)) { + ImageHelper.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), fos); + } } } }, handler).run(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java index 287f9abf0..bdde3e618 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java @@ -114,7 +114,9 @@ public class ShapeExporter { m.scale(settings.zoom); st.toImage(0, 0, 0, new RenderContext(), img, m, new CXFORMWITHALPHA()); if (settings.mode == ShapeExportMode.PNG) { - ImageHelper.write(img.getBufferedImage(), "PNG", new FileOutputStream(file)); + try (FileOutputStream fos = new FileOutputStream(file)) { + ImageHelper.write(img.getBufferedImage(), "PNG", fos); + } } else { BMPFile.saveBitmap(img.getBufferedImage(), file); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java index ad486858d..396a3fbcc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/helpers/BMPFile.java @@ -85,15 +85,9 @@ public class BMPFile extends Component { public static void saveBitmap(Image image, File file) throws IOException { BMPFile b = new BMPFile(); - b.fo = new FileOutputStream(file); - try { + try (FileOutputStream fos = new FileOutputStream(file)) { + b.fo = fos; b.save(image, image.getWidth(null), image.getHeight(null)); - } finally { - try { - b.fo.close(); - } catch (Exception ex) { - // ignore - } } } /* diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 703091b52..8a020e813 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -1119,7 +1119,9 @@ public class CommandLineArgumentParser { String xml = Helper.readTextFile(args.pop()); SWF swf = new SWF(); new SwfXmlImporter().importSwf(swf, xml); - swf.saveTo(new BufferedOutputStream(new FileOutputStream(args.pop()))); + try (FileOutputStream fos = new FileOutputStream(new File(args.pop()))) { + swf.saveTo(new BufferedOutputStream(fos)); + } } catch (IOException ex) { Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index b3aa0e9ec..c9d2cac31 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -390,27 +390,28 @@ public class Main { } File outfileF = new File(outfile); File tmpFile = new File(outfile + ".tmp"); - FileOutputStream fos = new FileOutputStream(tmpFile); - if (mode == SaveFileMode.EXE) { - InputStream exeStream = View.class.getClassLoader().getResourceAsStream("com/jpexs/helpers/resource/Swf2Exe.bin"); - byte[] buffer = new byte[4096]; - int bytesRead; - while ((bytesRead = exeStream.read(buffer)) != -1) { - fos.write(buffer, 0, bytesRead); + try (FileOutputStream fos = new FileOutputStream(tmpFile)) { + if (mode == SaveFileMode.EXE) { + InputStream exeStream = View.class.getClassLoader().getResourceAsStream("com/jpexs/helpers/resource/Swf2Exe.bin"); + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = exeStream.read(buffer)) != -1) { + fos.write(buffer, 0, bytesRead); + } + int width = swf.displayRect.Xmax - swf.displayRect.Xmin; + int height = swf.displayRect.Ymax - swf.displayRect.Ymin; + fos.write(width & 0xff); + fos.write((width >> 8) & 0xff); + fos.write((width >> 16) & 0xff); + fos.write((width >> 24) & 0xff); + fos.write(height & 0xff); + fos.write((height >> 8) & 0xff); + fos.write((height >> 16) & 0xff); + fos.write((height >> 24) & 0xff); + fos.write(Configuration.saveAsExeScaleMode.get()); } - int width = swf.displayRect.Xmax - swf.displayRect.Xmin; - int height = swf.displayRect.Ymax - swf.displayRect.Ymin; - fos.write(width & 0xff); - fos.write((width >> 8) & 0xff); - fos.write((width >> 16) & 0xff); - fos.write((width >> 24) & 0xff); - fos.write(height & 0xff); - fos.write((height >> 8) & 0xff); - fos.write((height >> 16) & 0xff); - fos.write((height >> 24) & 0xff); - fos.write(Configuration.saveAsExeScaleMode.get()); + swf.saveTo(fos); } - swf.saveTo(fos); if (tmpFile.exists()) { if (tmpFile.length() > 0) { outfileF.delete(); diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index b8def2260..56c3de277 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -980,7 +980,9 @@ public class PreviewPanel extends JSplitPane implements ActionListener { } try { tempFile = File.createTempFile("ffdec_view_", ".swf"); - swf.saveTo(new BufferedOutputStream(new FileOutputStream(tempFile))); + try (FileOutputStream fos = new FileOutputStream(tempFile)) { + swf.saveTo(new BufferedOutputStream(fos)); + } flashPanel.displaySWF(tempFile.getAbsolutePath(), backgroundColor, swf.frameRate); } catch (IOException iex) { Logger.getLogger(PreviewPanel.class.getName()).log(Level.SEVERE, "Cannot create tempfile", iex);