X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Ffile%2Fmotor%2FMotorLoaderHelper.java;h=13a2e423667757d5370893592d43368cab9a24ea;hb=4095cb0dd61a75b7b6b0bd811f8e803af5b27919;hp=049738a49a42e17a1ed99361f0106f7b8bb40f8f;hpb=ace80eeeeca723d4bd6f1cf6736f16b70055be8f;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/file/motor/MotorLoaderHelper.java b/core/src/net/sf/openrocket/file/motor/MotorLoaderHelper.java index 049738a4..13a2e423 100644 --- a/core/src/net/sf/openrocket/file/motor/MotorLoaderHelper.java +++ b/core/src/net/sf/openrocket/file/motor/MotorLoaderHelper.java @@ -19,13 +19,13 @@ import net.sf.openrocket.startup.Application; import net.sf.openrocket.util.Pair; public final class MotorLoaderHelper { - + private static final LogHelper log = Application.getLogger(); - + private MotorLoaderHelper() { // Prevent construction } - + /** * Load a file or directory of thrust curves. Directories are loaded * recursively. Any errors during loading are logged, but otherwise ignored. @@ -35,18 +35,18 @@ public final class MotorLoaderHelper { */ public static List load(File target) { GeneralMotorLoader loader = new GeneralMotorLoader(); - + if (target.isDirectory()) { - + try { return load(new DirectoryIterator(target, new SimpleFileFilter("", loader.getSupportedExtensions()), true)); } catch (IOException e) { log.warn("Could not read directory " + target, e); return Collections.emptyList(); } - + } else { - + InputStream is = null; try { is = new FileInputStream(target); @@ -63,11 +63,24 @@ public final class MotorLoaderHelper { } } } - + + } + } + + public static List load( InputStream is, String fileName ) { + GeneralMotorLoader loader = new GeneralMotorLoader(); + try { + List motors = loader.load(is, fileName); + if (motors.size() == 0) { + log.warn("No motors found in file " + fileName); + } + return motors; + } catch (IOException e) { + log.warn("IOException when loading motor file " + fileName, e); } + return Collections.emptyList(); } - - + /** * Load motors from files iterated over by a FileIterator. Any errors during * loading are logged, but otherwise ignored. @@ -78,22 +91,16 @@ public final class MotorLoaderHelper { * @return a list of all motors loaded. */ public static List load(FileIterator iterator) { - GeneralMotorLoader loader = new GeneralMotorLoader(); List list = new ArrayList(); - + while (iterator.hasNext()) { final Pair input = iterator.next(); log.debug("Loading motors from file " + input.getU()); try { - List motors = loader.load(input.getV(), input.getU()); - if (motors.size() == 0) { - log.warn("No motors found in file " + input.getU()); - } + List motors = load(input.getV(), input.getU()); for (Motor m : motors) { list.add((ThrustCurveMotor) m); } - } catch (IOException e) { - log.warn("IOException when loading motor file " + input.getU(), e); } finally { try { input.getV().close(); @@ -103,8 +110,8 @@ public final class MotorLoaderHelper { } } iterator.close(); - + return list; } - + }