public class HostName extends java.lang.Object implements HostIdentifierString, java.lang.Comparable<HostName>
IPAddressString
.
All manners of domain names are supported. You can add a prefix length to denote the subnet of the resolved address.
Validation is done separately from DNS resolution to avoid unnecessary lookups.
See rfc 3513, 2181, 952, 1035, 1034, 1123, 5890 or the list of rfcs for IPAddress. For IPv6 addresses in host, see rfc 2732 specifying [] notation and 3986 and 4038 (combining IPv6 [] with prefix or zone) and SMTP rfc 2821 for alternative uses of [] for both IPv4 and IPv6
Modifier and Type | Field and Description |
---|---|
static HostNameParameters |
DEFAULT_VALIDATION_OPTIONS |
static char |
IPV6_END_BRACKET |
static char |
IPV6_START_BRACKET |
static char |
LABEL_SEPARATOR |
static char |
PORT_SEPARATOR |
SEGMENT_VALUE_DELIMITER
Constructor and Description |
---|
HostName(java.net.InetAddress inetAddr) |
HostName(java.net.InetAddress inetAddr,
IPAddressStringParameters addressOptions) |
HostName(IPAddress addr) |
HostName(java.lang.String host) |
HostName(java.lang.String host,
HostNameParameters options) |
Modifier and Type | Method and Description |
---|---|
IPAddress |
asAddress()
If this represents an ip address, returns that address.
|
IPAddress |
asAddress(IPAddress.IPVersion version)
If this represents an ip address, returns that address.
|
IPAddressString |
asAddressString()
If this represents an ip address or represents a valid IPAddressString, returns the corresponding address string.
|
int |
compareTo(HostName other) |
boolean |
equals(java.lang.Object o) |
IPAddress |
getAddress()
If this represents an ip address, returns that address.
|
AddressStringException |
getAddressStringException()
Returns the exception thrown for invalid ipv6 literal or invalid reverse DNS hosts.
|
java.lang.String |
getHost()
Returns the host string normalized but without port, service, prefix or mask.
|
java.lang.Integer |
getNetworkPrefixLength()
If a prefix was supplied, either as part of an address or as part of a domain (in which case the prefix applies to any resolved address),
then returns that prefix length.
|
java.lang.String[] |
getNormalizedLabels() |
java.lang.Integer |
getPort()
If a port was supplied, returns the port, otherwise returns null
|
java.lang.String |
getService()
If a service name was supplied, returns the service name, otherwise returns null
|
HostNameParameters |
getValidationOptions() |
int |
hashCode() |
boolean |
isAddress() |
boolean |
isAddress(IPAddress.IPVersion version) |
boolean |
isAddressString() |
boolean |
isAllAddresses() |
boolean |
isEmpty()
Returns true if the address is empty (zero-length).
|
boolean |
isLocalHost() |
boolean |
isLoopback() |
boolean |
isPrefixOnly() |
boolean |
isReverseDNS() |
boolean |
isSelf() |
boolean |
isUNCIPv6Literal() |
boolean |
isValid() |
boolean |
matches(HostName host) |
boolean |
resolvesToSelf() |
IPAddress |
toAddress()
If this represents an ip address, returns that address.
|
java.net.InetAddress |
toInetAddress() |
java.lang.String |
toNormalizedString()
provides a normalized String representation for the host identified by this HostIdentifierString instance
|
java.lang.String |
toString() |
void |
validate() |
public static final char LABEL_SEPARATOR
public static final char IPV6_START_BRACKET
public static final char IPV6_END_BRACKET
public static final char PORT_SEPARATOR
public static final HostNameParameters DEFAULT_VALIDATION_OPTIONS
public HostName(IPAddress addr)
public HostName(java.net.InetAddress inetAddr)
public HostName(java.net.InetAddress inetAddr, IPAddressStringParameters addressOptions)
public HostName(java.lang.String host)
public HostName(java.lang.String host, HostNameParameters options)
public HostNameParameters getValidationOptions()
public void validate() throws HostNameException
validate
in interface HostIdentifierString
HostNameException
public boolean isValid()
public boolean resolvesToSelf()
public boolean isSelf()
public boolean isLocalHost()
public boolean isLoopback()
public java.net.InetAddress toInetAddress() throws HostNameException, java.net.UnknownHostException
HostNameException
java.net.UnknownHostException
public java.lang.String toNormalizedString()
HostIdentifierString
toNormalizedString
in interface HostIdentifierString
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String[] getNormalizedLabels()
public java.lang.String getHost()
public boolean matches(HostName host)
public int compareTo(HostName other)
compareTo
in interface java.lang.Comparable<HostName>
public boolean isAddress(IPAddress.IPVersion version)
public boolean isAddress()
public boolean isAddressString()
public boolean isAllAddresses()
public boolean isPrefixOnly()
public boolean isEmpty()
public java.lang.Integer getPort()
public java.lang.String getService()
public AddressStringException getAddressStringException()
public boolean isUNCIPv6Literal()
public boolean isReverseDNS()
public IPAddressString asAddressString()
public IPAddress asAddress()
public IPAddress asAddress(IPAddress.IPVersion version)
toAddress()
or getAddress()
to get the resolved address.public java.lang.Integer getNetworkPrefixLength()
public IPAddress toAddress() throws java.net.UnknownHostException, HostNameException
getAddress()
will simply return null rather than throw those exceptions.
If you wish to get the represented address and avoid DNS resolution, use asAddress()
or asAddressString()
toAddress
in interface HostIdentifierString
java.net.UnknownHostException
HostNameException
public IPAddress getAddress()
asAddress()
or asAddressString()
getAddress
in interface HostIdentifierString
public java.lang.String toString()
toString
in class java.lang.Object