Commit 3cc4e501 authored by Luc Maisonobe's avatar Luc Maisonobe

Improved error handling in tutorials input files.

parent 205588b0
......@@ -98,19 +98,23 @@ public class KeyValueFileParser<Key extends Enum<Key>> {
* </p>
* @param input input stream
* @exception IOException if input file cannot be read
* @exception IllegalArgumentException if a line cannot be read properly
* @exception OrekitException if a line cannot be read properly
*/
public void parseInput(final InputStream input) throws IOException, IllegalArgumentException {
public void parseInput(final String name, final InputStream input)
throws IOException, OrekitException {
final Pattern arrayPattern = Pattern.compile("([\\w\\.]+)\\s*\\[([0-9]+)\\]");
final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
int lineNumber = 0;
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
++lineNumber;
line = line.trim();
// we ignore blank lines and line starting with '#'
if ((line.length() > 0) && !line.startsWith("#")) {
String[] fields = line.split("\\s*=\\s*");
if (fields.length != 2) {
throw new IllegalArgumentException(line);
throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE,
lineNumber, name, line);
}
final Matcher matcher = arrayPattern.matcher(fields[0]);
if (matcher.matches()) {
......
......@@ -165,7 +165,7 @@ public class Phasing {
// read input parameters
KeyValueFileParser<ParameterKey> parser =
new KeyValueFileParser<ParameterKey>(ParameterKey.class);
parser.parseInput(new FileInputStream(input));
parser.parseInput(input.getAbsolutePath(), new FileInputStream(input));
TimeScale utc = TimeScalesFactory.getUTC();
// simulation properties
......
......@@ -205,7 +205,7 @@ public class DSSTPropagation {
// read input parameters
KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class);
parser.parseInput(new FileInputStream(input));
parser.parseInput(input.getAbsolutePath(), new FileInputStream(input));
// check mandatory input parameters
if (!parser.containsKey(ParameterKey.ORBIT_DATE)) {
......
......@@ -121,7 +121,7 @@ public class TrackCorridor {
// read input parameters
KeyValueFileParser<ParameterKey> parser =
new KeyValueFileParser<ParameterKey>(ParameterKey.class);
parser.parseInput(new FileInputStream(input));
parser.parseInput(input.getAbsolutePath(), new FileInputStream(input));
TimeScale utc = TimeScalesFactory.getUTC();
Propagator propagator;
......
......@@ -97,7 +97,7 @@ public class VisibilityCircle {
// read input parameters
KeyValueFileParser<ParameterKey> parser =
new KeyValueFileParser<ParameterKey>(ParameterKey.class);
parser.parseInput(new FileInputStream(input));
parser.parseInput(input.getAbsolutePath(), new FileInputStream(input));
double minElevation = parser.getAngle(ParameterKey.MIN_ELEVATION);
double radius = Constants.WGS84_EARTH_EQUATORIAL_RADIUS +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment