mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-07-09 02:28:22 +00:00
#798 close file streams after export
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
} else {
|
||||
try (FileOutputStream fos = new FileOutputStream(file)) {
|
||||
ImageHelper.write(imageTag.getImage().getBufferedImage(), ffileFormat.toUpperCase(Locale.ENGLISH), fos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, handler).run();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user