1 package net.sf.openrocket.file;
3 import java.io.IOException;
4 import java.io.InputStream;
6 import java.nio.charset.Charset;
9 import net.sf.openrocket.file.motor.RASPMotorLoader;
10 import net.sf.openrocket.file.motor.RockSimMotorLoader;
11 import net.sf.openrocket.motor.Motor;
14 * A motor loader class that detects the file type based on the file name extension.
16 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
18 public class GeneralMotorLoader extends MotorLoader {
20 private static final MotorLoader RASP_LOADER = new RASPMotorLoader();
21 private static final MotorLoader ROCKSIM_LOADER = new RockSimMotorLoader();
25 public List<Motor> load(InputStream stream, String filename) throws IOException {
26 return selectLoader(filename).load(stream, filename);
30 public List<Motor> load(Reader reader, String filename) throws IOException {
31 return selectLoader(filename).load(reader, filename);
36 protected Charset getDefaultCharset() {
37 // Not used, may return null
43 * Return the appropriate motor loader based on the file name.
45 * @param filename the file name (may be <code>null</code>).
46 * @return the appropriate motor loader to use for the file.
47 * @throws IOException if the file type cannot be detected from the file name.
49 public static MotorLoader selectLoader(String filename) throws IOException {
50 if (filename == null) {
51 throw new IOException("Unknown file type.");
55 int point = filename.lastIndexOf('.');
58 ext = filename.substring(point+1);
60 if (ext.equalsIgnoreCase("eng")) {
62 } else if (ext.equalsIgnoreCase("rse")) {
63 return ROCKSIM_LOADER;
66 throw new IOException("Unknown file type.");