1 package net.sf.openrocket.file;
3 import java.awt.Component;
4 import java.io.BufferedInputStream;
6 import java.io.FileInputStream;
7 import java.io.FileNotFoundException;
8 import java.io.IOException;
9 import java.io.InputStream;
11 import javax.swing.ProgressMonitorInputStream;
13 import net.sf.openrocket.aerodynamics.WarningSet;
14 import net.sf.openrocket.document.OpenRocketDocument;
17 public abstract class RocketLoader {
18 protected final WarningSet warnings = new WarningSet();
21 public final OpenRocketDocument load(File source, Component parent)
22 throws RocketLoadException {
26 return load(new BufferedInputStream(new ProgressMonitorInputStream(
27 parent, "Loading " + source.getName(),
28 new FileInputStream(source))));
29 } catch (FileNotFoundException e) {
30 throw new RocketLoadException("File not found: " + source);
35 * Loads a rocket from the specified File object.
37 public final OpenRocketDocument load(File source) throws RocketLoadException {
41 return load(new BufferedInputStream(new FileInputStream(source)));
42 } catch (FileNotFoundException e) {
43 throw new RocketLoadException("File not found: " + source);
48 * Loads a rocket from the specified InputStream.
50 public final OpenRocketDocument load(InputStream source) throws RocketLoadException {
54 return loadFromStream(source);
55 } catch (RocketLoadException e) {
57 } catch (IOException e) {
58 throw new RocketLoadException("I/O error: " + e.getMessage());
59 } catch (Exception e) {
60 throw new RocketLoadException("An unknown error occurred. Please report a bug.", e);
61 } catch (Throwable e) {
62 throw new RocketLoadException("A serious error occurred and the software may be "
63 + "unstable. Save your designs and restart OpenRocket.", e);
70 * This method is called by the default implementations of {@link #load(File)}
71 * and {@link #load(InputStream)} to load the rocket.
73 * @throws RocketLoadException if an error occurs during loading.
75 protected abstract OpenRocketDocument loadFromStream(InputStream source) throws IOException,
80 public final WarningSet getWarnings() {