1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.ini4j.spi;
17
18 import org.ini4j.Config;
19 import org.ini4j.InvalidFileFormatException;
20
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.Reader;
24
25 import java.net.URL;
26
27 public class OptionsParser extends AbstractParser
28 {
29 private static final String COMMENTS = "!#";
30 private static final String OPERATORS = ":=";
31
32 public OptionsParser()
33 {
34 super(OPERATORS, COMMENTS);
35 }
36
37 public static OptionsParser newInstance()
38 {
39 return ServiceFinder.findService(OptionsParser.class);
40 }
41
42 public static OptionsParser newInstance(Config config)
43 {
44 OptionsParser instance = newInstance();
45
46 instance.setConfig(config);
47
48 return instance;
49 }
50
51 public void parse(InputStream input, OptionsHandler handler) throws IOException, InvalidFileFormatException
52 {
53 parse(newIniSource(input, handler), handler);
54 }
55
56 public void parse(Reader input, OptionsHandler handler) throws IOException, InvalidFileFormatException
57 {
58 parse(newIniSource(input, handler), handler);
59 }
60
61 public void parse(URL input, OptionsHandler handler) throws IOException, InvalidFileFormatException
62 {
63 parse(newIniSource(input, handler), handler);
64 }
65
66 private void parse(IniSource source, OptionsHandler handler) throws IOException, InvalidFileFormatException
67 {
68 handler.startOptions();
69 for (String line = source.readLine(); line != null; line = source.readLine())
70 {
71 parseOptionLine(line, handler, source.getLineNumber());
72 }
73
74 handler.endOptions();
75 }
76 }