Package org.xbill.DNS.hosts
Class HostsFileParser
java.lang.Object
org.xbill.DNS.hosts.HostsFileParser
Parses and caches the system's local hosts database, otherwise known as
/etc/hosts. The
cache is cleared when the file is modified.- Since:
- 3.4
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance based on the current OS's default.HostsFileParser(Path path) Creates an instance with a custom hosts database path.HostsFileParser(Path path, boolean clearCacheOnChange) Creates an instance with a custom hosts database path. -
Method Summary
Modifier and TypeMethodDescriptiongetAddressForHost(Name name, int type) Performs on-demand parsing and caching of the local hosts database.
-
Constructor Details
-
HostsFileParser
public HostsFileParser()Creates a new instance based on the current OS's default. Unix and alike (or rather everything else than Windows) use/etc/hosts, while on Windows%SystemRoot%\System32\drivers\etc\hostsis used. The cache is cleared when the file has changed. -
HostsFileParser
Creates an instance with a custom hosts database path. The cache is cleared when the file has changed.- Parameters:
path- The path to the hosts database.
-
HostsFileParser
Creates an instance with a custom hosts database path.- Parameters:
path- The path to the hosts database.clearCacheOnChange- set to true to clear the cache when the hosts file changes.
-
-
Method Details
-
getAddressForHost
Performs on-demand parsing and caching of the local hosts database.- Parameters:
name- the hostname to search for.type- Record type to search for, seeType.- Returns:
- The first address found for the requested hostname.
- Throws:
IOException- When the parsing fails.IllegalArgumentException- whentypeis notType.AorType.AAAA.
-