| 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 | 30 | super(OPERATORS, COMMENTS); |
| 35 | 30 | } |
| 36 | |
|
| 37 | |
public static OptionsParser newInstance() |
| 38 | |
{ |
| 39 | 26 | return ServiceFinder.findService(OptionsParser.class); |
| 40 | |
} |
| 41 | |
|
| 42 | |
public static OptionsParser newInstance(Config config) |
| 43 | |
{ |
| 44 | 25 | OptionsParser instance = newInstance(); |
| 45 | |
|
| 46 | 25 | instance.setConfig(config); |
| 47 | |
|
| 48 | 25 | return instance; |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void parse(InputStream input, OptionsHandler handler) throws IOException, InvalidFileFormatException |
| 52 | |
{ |
| 53 | 1 | parse(newIniSource(input, handler), handler); |
| 54 | 0 | } |
| 55 | |
|
| 56 | |
public void parse(Reader input, OptionsHandler handler) throws IOException, InvalidFileFormatException |
| 57 | |
{ |
| 58 | 19 | parse(newIniSource(input, handler), handler); |
| 59 | 16 | } |
| 60 | |
|
| 61 | |
public void parse(URL input, OptionsHandler handler) throws IOException, InvalidFileFormatException |
| 62 | |
{ |
| 63 | 8 | parse(newIniSource(input, handler), handler); |
| 64 | 8 | } |
| 65 | |
|
| 66 | |
private void parse(IniSource source, OptionsHandler handler) throws IOException, InvalidFileFormatException |
| 67 | |
{ |
| 68 | 28 | handler.startOptions(); |
| 69 | 784 | for (String line = source.readLine(); line != null; line = source.readLine()) |
| 70 | |
{ |
| 71 | 760 | parseOptionLine(line, handler, source.getLineNumber()); |
| 72 | |
} |
| 73 | |
|
| 74 | 24 | handler.endOptions(); |
| 75 | 24 | } |
| 76 | |
} |