net.i2p.addressbook

## Class HostTxtParser

- java.lang.Object
- - net.i2p.addressbook.HostTxtParser

-     public class HostTxtParser
      extends Object

  Utility class providing methods to parse and write files in a hosts.txt file format, and subscription file format.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `main(String[] args)` Usage: HostTxtParser [-q] validate example.i2p=b64dest[#!key1=val1#key2=val2]
    `static Map<String,HostTxtEntry>` | `parse(File file)` 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` | `parse(String inputLine, boolean allowCommandOnly)` 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### main

          public static void main(String[] args)
                           throws Exception

      Usage: HostTxtParser [-q] validate example.i2p=b64dest[#!key1=val1#key2=val2]
      Throws:
        `Exception`

    - #### parse

          public static Map<String,HostTxtEntry> parse(File file)
                                                throws IOException

      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

          public static Map<String,HostTxtEntry> parse(File file,
                                                       Map<String,HostTxtEntry> 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. 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.

    - #### parse

          public static HostTxtEntry parse(String inputLine,
                                           boolean allowCommandOnly)

      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

    - #### write

          public static void write(Map<String,HostTxtEntry> 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.