Package net.i2p.addressbook
Class ConfigParser
- java.lang.Object
-
- net.i2p.addressbook.ConfigParser
-
class ConfigParser extends Object
Utility class providing methods to parse and write files in config file format, and subscription file format. TODO: switch to the DataHelper loadProps/storeProps methods?- Author:
- Ragnarok
-
-
Constructor Summary
Constructors Constructor Description ConfigParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Map<String,String>
parse(File file)
Return a Map using the contents of the File file.static Map<String,String>
parse(File file, Map<String,String> map)
Return a Map using the contents of the File file.static List<String>
parseSubscriptions(File file, List<String> list)
Return a List using the contents of the File file.static String
stripComments(String inputLine)
Strip the comments from a String.static void
write(Map<String,String> map, File file)
Write contents of Map map to the File file.
-
-
-
Method Detail
-
stripComments
public static String stripComments(String inputLine)
Strip the comments from a String. Lines that begin with '#' and ';' are considered comments, as well as any part of a line after a '#'.- Parameters:
inputLine
- A String to strip comments from.- Returns:
- A String without comments, but otherwise identical to inputLine.
-
parse
public static Map<String,String> parse(File file) throws IOException
Return a Map using the contents of the File file. See parseBufferedReader for details of the input format.- Parameters:
file
- A File to parse.- Returns:
- A Map containing the key, value pairs from file.
- Throws:
IOException
- if file cannot be read.
-
parse
public static Map<String,String> parse(File file, Map<String,String> map)
Return a Map using the contents of the File file. If file cannot be read, use map instead, and write the result to where file should have been.- Parameters:
file
- A File to attempt to parse.map
- A Map containing values to use as defaults.- Returns:
- A Map containing the key, value pairs from file, or if file cannot be read, map.
-
parseSubscriptions
public static List<String> parseSubscriptions(File file, List<String> list)
Return a List using the contents of the File file. If file cannot be read, use list instead, and write the result to where file should have been.- Parameters:
file
- A File to attempt to parse.list
- The default subscriptions to be saved and returned if the file cannot be read- Returns:
- A List consisting of one element for each line in file, or if file cannot be read, list.
-
write
public static void write(Map<String,String> map, File file) throws IOException
Write contents of Map map to the File file. Output is written with one key, value pair on each line, in the format: key=value. Write to a temp file in the same directory and then rename, to not corrupt simultaneous accesses by the router. Except on Windows where renameTo() will fail if the target exists.- Parameters:
map
- A Map to write to file.file
- A File to write the Map to.- Throws:
IOException
- if file cannot be written to.
-
-