1 package net.sf.openrocket.file;
3 import java.io.BufferedInputStream;
5 import java.io.FileInputStream;
6 import java.io.FileNotFoundException;
7 import java.io.IOException;
8 import java.io.InputStream;
10 import net.sf.openrocket.aerodynamics.WarningSet;
11 import net.sf.openrocket.document.OpenRocketDocument;
14 public abstract class RocketLoader {
15 protected final WarningSet warnings = new WarningSet();
19 * Loads a rocket from the specified File object.
21 public final OpenRocketDocument load(File source) throws RocketLoadException {
25 return load(new BufferedInputStream(new FileInputStream(source)));
26 } catch (FileNotFoundException e) {
27 throw new RocketLoadException("File not found: " + source);
32 * Loads a rocket from the specified InputStream.
34 public final OpenRocketDocument load(InputStream source) throws RocketLoadException {
38 return loadFromStream(source);
39 } catch (RocketLoadException e) {
41 } catch (IOException e) {
42 throw new RocketLoadException("I/O error: " + e.getMessage());
43 } catch (Exception e) {
44 throw new RocketLoadException("An unknown error occurred. Please report a bug.", e);
45 } catch (Throwable e) {
46 throw new RocketLoadException("A serious error occurred and the software may be "
47 + "unstable. Save your designs and restart OpenRocket.", e);
54 * This method is called by the default implementations of {@link #load(File)}
55 * and {@link #load(InputStream)} to load the rocket.
57 * @throws RocketLoadException if an error occurs during loading.
59 protected abstract OpenRocketDocument loadFromStream(InputStream source) throws IOException,
64 public final WarningSet getWarnings() {