#798 close file streams after export

This commit is contained in:
2015-02-11 18:26:22 +01:00
parent 4106f764bf
commit f2922421cb
8 changed files with 45 additions and 37 deletions
@@ -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);
}
+20 -19
View File
@@ -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);