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.rocketcomponent.Motor;
12 * A motor loader class that detects the file type based on the file name extension.
14 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
16 public class GeneralMotorLoader extends MotorLoader {
18 private static final MotorLoader RASP_LOADER = new RASPMotorLoader();
19 private static final MotorLoader ROCKSIM_LOADER = new RockSimMotorLoader();
23 public List<Motor> load(InputStream stream, String filename) throws IOException {
24 return selectLoader(filename).load(stream, filename);
28 public List<Motor> load(Reader reader, String filename) throws IOException {
29 return selectLoader(filename).load(reader, filename);
34 protected Charset getDefaultCharset() {
35 // Not used, may return null
41 * Return the appropriate motor loader based on the file name.
43 * @param filename the file name (may be <code>null</code>).
44 * @return the appropriate motor loader to use for the file.
45 * @throws IOException if the file type cannot be detected from the file name.
47 public static MotorLoader selectLoader(String filename) throws IOException {
48 if (filename == null) {
49 throw new IOException("Unknown file type.");
53 int point = filename.lastIndexOf('.');
56 ext = filename.substring(point+1);
58 if (ext.equalsIgnoreCase("eng")) {
60 } else if (ext.equalsIgnoreCase("rse")) {
61 return ROCKSIM_LOADER;
64 throw new IOException("Unknown file type.");