From 52e9e37b0f55366efaa921ed5e8373f9000ea522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 3 Aug 2013 13:41:59 +0200 Subject: [PATCH] Issue #286 Saving to temp file first --- .../src/com/jpexs/decompiler/flash/gui/Main.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java index 3d2964a9e..1853766c0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/Main.java @@ -224,7 +224,20 @@ public class Main { public static void saveFile(String outfile) throws IOException { file = outfile; - swf.saveTo(new FileOutputStream(outfile)); + File outfileF = new File(outfile); + File tmpFile = new File(outfile+".tmp"); + swf.saveTo(new FileOutputStream(tmpFile)); + if(tmpFile.exists()){ + if(tmpFile.length() > 0){ + outfileF.delete(); + if (!tmpFile.renameTo(outfileF)) { + tmpFile.delete(); + throw new IOException("Cannot access " + outfile); + } + }else{ + throw new IOException("Output is empty"); + } + } } private static class OpenFileWorker extends SwingWorker {