Issue #286 Saving to temp file first

This commit is contained in:
Jindra Petk
2013-08-03 13:41:59 +02:00
parent f29a8e0df6
commit 52e9e37b0f

View File

@@ -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 {