Class HostsFileParser

java.lang.Object
org.xbill.DNS.hosts.HostsFileParser

public final class HostsFileParser extends Object
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
  • Field Details

    • maxFullCacheFileSizeBytes

      private final int maxFullCacheFileSizeBytes
    • fileChangeCheckInterval

      private final Duration fileChangeCheckInterval
    • path

      private final Path path
    • clearCacheOnChange

      private final boolean clearCacheOnChange
    • clock

      private Clock clock
    • hostsCache

      private volatile Map<String,InetAddress> hostsCache
    • lastFileModificationCheckTime

      private Instant lastFileModificationCheckTime
    • lastFileReadTime

      private Instant lastFileReadTime
    • isEntireFileParsed

      private boolean isEntireFileParsed
    • hostsFileWarningLogged

      private boolean hostsFileWarningLogged
    • hostsFileSizeBytes

      private long hostsFileSizeBytes
  • 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\hosts is used. The cache is cleared when the file has changed.
    • HostsFileParser

      public HostsFileParser(Path path)
      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

      public HostsFileParser(Path path, boolean clearCacheOnChange)
      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