22 private static final int MAX_ERRORS = 20;
23 private static final int MAX_LINES = 500;
25 private final HashMap<String, Object> options;
29 options =
new HashMap<>();
32 public void parse(Reader reader)
throws IOException
34 BufferedReader br =
new BufferedReader(reader);
41 while ((line = br.readLine()) !=
null)
46 if (errors > MAX_ERRORS || lines > MAX_LINES)
49 throw new IOException(
"Parsing limits exceeded");
52 String[] fields = line.split(
":", 3);
54 if (fields.length == 3)
56 if (fields[1].equals(
"s"))
58 options.put(fields[0].toLowerCase(Locale.ENGLISH), fields[2]);
61 else if (fields[1].equals(
"i"))
65 Integer i = Integer.parseInt(fields[2]);
66 options.put(fields[0].toLowerCase(Locale.ENGLISH), i);
69 catch (NumberFormatException e)
73 else if (fields[1].equals(
"b"))
85 public String getString(String optionName)
87 if (options.get(optionName) instanceof String)
88 return (String)options.get(optionName);
93 public Integer getInteger(String optionName)
95 if (options.get(optionName) instanceof Integer)
96 return (Integer)options.get(optionName);