Package net.i2p.addressbook
Class HostTxtParser
java.lang.Object
net.i2p.addressbook.HostTxtParser
Utility class providing methods to parse and write files in a hosts.txt file
format, and subscription file format.
- Since:
- 0.9.26 modified from ConfigParser, public since 0.9.55 for CLI
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Usage: HostTxtParser [-q] validate example.i2p=b64dest[#!key1=val1#key2=val2]static Map<String,
HostTxtEntry> Return a Map using the contents of the File file.static Map<String,
HostTxtEntry> parse
(File file, Map<String, HostTxtEntry> map) Return a Map using the contents of the File file.static HostTxtEntry
Return a HostTxtEntry from the contents of the inputLine.static void
write
(Map<String, HostTxtEntry> map, File file) Write contents of Map map to the File file.
-
Constructor Details
-
HostTxtParser
public HostTxtParser()
-
-
Method Details
-
parse
Return a HostTxtEntry from the contents of the inputLine.- Parameters:
inputLine
- key=value[#!k1=v1#k2=v2...]allowCommandOnly
- if true, a line starting with #! will return a HostTxtEntry with a null name and dest and non-null props. If false, these lines will return null.- Returns:
- null if no entry found or on error
-
parse
Return a Map using the contents of the File file. See parse(BufferedReader) for details of the input format. Returned map will not contain null ("remove") entries.- Parameters:
file
- A File to parse.- Returns:
- A Map containing the key, value pairs from file.
- Throws:
IOException
- if file cannot be read.
-
parse
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. Returned map will not contain null ("remove") entries.- 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.
-
write
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.
-
main
Usage: HostTxtParser [-q] validate example.i2p=b64dest[#!key1=val1#key2=val2]- Throws:
Exception
-