1 package net.sf.openrocket.util;
3 import java.io.BufferedOutputStream;
5 import java.io.FileOutputStream;
7 import javax.swing.SwingWorker;
9 import net.sf.openrocket.document.OpenRocketDocument;
10 import net.sf.openrocket.file.RocketSaver;
11 import net.sf.openrocket.gui.main.ExceptionHandler;
13 public class SaveFileWorker extends SwingWorker<Void, Void> {
15 private final OpenRocketDocument document;
16 private final File file;
17 private final RocketSaver saver;
19 public SaveFileWorker(OpenRocketDocument document, File file, RocketSaver saver) {
20 this.document = document;
27 protected Void doInBackground() throws Exception {
29 int estimate = (int)saver.estimateFileSize(document,
30 document.getDefaultStorageOptions());
32 // Create the ProgressOutputStream that provides progress estimates
33 ProgressOutputStream os = new ProgressOutputStream(
34 new BufferedOutputStream(new FileOutputStream(file)),
38 protected void setProgress(int progress) {
39 SaveFileWorker.this.setProgress(progress);
45 saver.save(os, document);
49 } catch (Exception e) {
50 ExceptionHandler.handleErrorCondition("Error closing file", e);