import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.openrocket.importt.OpenRocketLoader;
import net.sf.openrocket.file.rocksim.importt.RocksimLoader;
+import net.sf.openrocket.util.ArrayUtils;
+import net.sf.openrocket.util.TextUtil;
/**
private static final int READ_BYTES = 300;
private static final byte[] GZIP_SIGNATURE = { 31, -117 }; // 0x1f, 0x8b
- private static final byte[] ZIP_SIGNATURE = "PK".getBytes(Charset.forName("US-ASCII"));
- private static final byte[] OPENROCKET_SIGNATURE = "<openrocket".getBytes(Charset.forName("US-ASCII"));
- private static final byte[] ROCKSIM_SIGNATURE = "<RockSimDoc".getBytes(Charset.forName("US-ASCII"));
+ private static final byte[] ZIP_SIGNATURE = TextUtil.convertStringToBytes("PK",Charset.forName("US-ASCII"));
+ private static final byte[] OPENROCKET_SIGNATURE = TextUtil.convertStringToBytes("<openrocket",Charset.forName("US-ASCII"));
+ private static final byte[] ROCKSIM_SIGNATURE = TextUtil.convertStringToBytes("<RockSimDoc",Charset.forName("US-ASCII"));
private final OpenRocketLoader openRocketLoader = new OpenRocketLoader();
private final RocksimLoader rocksimLoader = new RocksimLoader();
@Override
- protected OpenRocketDocument loadFromStream(InputStream source) throws IOException,
+ protected OpenRocketDocument loadFromStream(InputStream source, MotorFinder motorFinder) throws IOException,
RocketLoadException {
// Check for mark() support
// Check for GZIP
if (buffer[0] == GZIP_SIGNATURE[0] && buffer[1] == GZIP_SIGNATURE[1]) {
- OpenRocketDocument doc = loadFromStream(new GZIPInputStream(source));
+ OpenRocketDocument doc = loadFromStream(new GZIPInputStream(source), motorFinder);
doc.getDefaultStorageOptions().setCompressionEnabled(true);
return doc;
}
throw new RocketLoadException("Unsupported or corrupt file.");
}
if (entry.getName().matches(".*\\.[oO][rR][kK]$")) {
- OpenRocketDocument doc = loadFromStream(in);
+ OpenRocketDocument doc = loadFromStream(in, motorFinder);
doc.getDefaultStorageOptions().setCompressionEnabled(true);
return doc;
+ } else if ( entry.getName().matches(".*\\.[rR][kK][tT]$")) {
+ OpenRocketDocument doc = loadFromStream(in, motorFinder);
+ return doc;
}
}
}
if (buffer[i] == OPENROCKET_SIGNATURE[match]) {
match++;
if (match == OPENROCKET_SIGNATURE.length) {
- return loadUsing(source, openRocketLoader);
+ return loadUsing(source, openRocketLoader, motorFinder);
}
} else {
match = 0;
}
}
- byte[] typeIdentifier = Arrays.copyOf(buffer, ROCKSIM_SIGNATURE.length);
+ byte[] typeIdentifier = ArrayUtils.copyOf(buffer, ROCKSIM_SIGNATURE.length);
if (Arrays.equals(ROCKSIM_SIGNATURE, typeIdentifier)) {
- return loadUsing(source, rocksimLoader);
+ return loadUsing(source, rocksimLoader, motorFinder);
}
throw new RocketLoadException("Unsupported or corrupt file.");
}
- private OpenRocketDocument loadUsing(InputStream source, RocketLoader loader)
+ private OpenRocketDocument loadUsing(InputStream source, RocketLoader loader, MotorFinder motorFinder)
throws RocketLoadException {
warnings.clear();
- OpenRocketDocument doc = loader.load(source);
+ OpenRocketDocument doc = loader.load(source, motorFinder);
warnings.addAll(loader.getWarnings());
return doc;
}