Class DnsStringLookup

java.lang.Object
org.apache.commons.text.lookup.AbstractStringLookup
org.apache.commons.text.lookup.DnsStringLookup
All Implemented Interfaces:
StringLookup

final class DnsStringLookup extends AbstractStringLookup
Looks up keys related to DNS entries like host name, canonical host name, host address.

The lookup keys are:

  • name|address: for the host name, for example "name|93.184.216.34" -> "example.com".
  • canonical-name|address: for the canonical host name, for example "name|93.184.216.34" -> "example.com".
  • address|hostname: for the host address, for example "address|example.com" -> "93.184.216.34".
  • address: same as address|hostname.

Using a StringLookup from the StringLookupFactory:

 StringLookupFactory.INSTANCE.dnsStringLookup().lookup("address|apache.org");
 

Using a StringSubstitutor:

 StringSubstitutor.createInterpolator().replace("... ${dns:address|apache.org} ..."));
 

The above examples convert "address|apache.org" to "95.216.24.32 (or "40.79.78.1").

Since:
1.8
  • Field Details

    • INSTANCE

      static final DnsStringLookup INSTANCE
      Defines the singleton for this class.
  • Constructor Details

    • DnsStringLookup

      private DnsStringLookup()
      No need to build instances for now.
  • Method Details

    • lookup

      public String lookup(String key)
      Looks up the DNS value of the key.
      Parameters:
      key - the key to be looked up, may be null
      Returns:
      The DNS value.