Top Description Inners Methods
java.net.spi

public Interface InetAddressResolver

Known Direct Implementers
java.net.InetAddress.PlatformResolver, java.net.InetAddress.HostsFileResolver
Imports
java.lang.annotation.Native, java.net.InetAddress, .UnknownHostException, java.util.stream.Stream

This interface defines operations for looking up host names and IP addresses. InetAddress delegates all lookup operations to the system-wide resolver.

The system-wide resolver can be customized by deploying an implementation of InetAddressResolverProvider.

Since
18

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
InetAddressResolver.LookupPolicy

A LookupPolicy object describes characteristics that can be applied to a lookup operation.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

String representing the host name mapping
lookupByAddress
(byte[]
byte array representing a raw IP address
addr
)

Lookup the host name corresponding to the raw IP address provided.

public Stream<InetAddress>

Returns:

a stream of IP addresses for the requested host
lookupByName
(String
the specified hostname
host
,
InetAddressResolver.LookupPolicy
the address lookup policy
lookupPolicy
)

Given the name of a host, returns a stream of IP addresses of the requested address family associated with a provided hostname.

Method Detail

lookupByAddressback to summary
public String lookupByAddress(byte[] addr) throws UnknownHostException

Lookup the host name corresponding to the raw IP address provided.

addr argument is in network byte order: the highest order byte of the address is in addr[0].

IPv4 address byte array must be 4 bytes long and IPv6 byte array must be 16 bytes long.

Parameters
addr:byte[]

byte array representing a raw IP address

Returns:String

String representing the host name mapping

Exceptions
UnknownHostException:
if no host name is found for the specified IP address
IllegalArgumentException:
if the length of the provided byte array doesn't correspond to a valid IP address length
NullPointerException:
if addr is null
lookupByNameback to summary
public Stream<InetAddress> lookupByName(String host, InetAddressResolver.LookupPolicy lookupPolicy) throws UnknownHostException

Given the name of a host, returns a stream of IP addresses of the requested address family associated with a provided hostname.

host should be a machine name, such as "www.example.com", not a textual representation of its IP address. No validation is performed on the given host name: if a textual representation is supplied, the name resolution is likely to fail and UnknownHostException may be thrown.

The address family type and addresses order are specified by the LookupPolicy instance. Lookup operation characteristics could be acquired with LookupPolicy#characteristics(). If InetAddressResolver.LookupPolicy#IPV4 and InetAddressResolver.LookupPolicy#IPV6 characteristics provided then this method returns addresses of both IPV4 and IPV6 families.

Parameters
host:String

the specified hostname

lookupPolicy:InetAddressResolver.LookupPolicy

the address lookup policy

Returns:Stream<InetAddress>

a stream of IP addresses for the requested host

Exceptions
UnknownHostException:
if no IP address for the host could be found
NullPointerException:
if either parameter is null
See Also
LookupPolicy
java.net.spi back to summary

public final Class InetAddressResolver.LookupPolicy

extends Object
Class Inheritance

A LookupPolicy object describes characteristics that can be applied to a lookup operation. In particular, it is used to specify the ordering and which filtering should be performed when looking up host addresses.

The default platform-wide lookup policy is constructed by consulting System Properties which affect how IPv4 and IPv6 addresses are returned.

Since
18

Field Summary

Modifier and TypeField and Description
private final int
public static final int
IPV4

Characteristic value signifying if IPv4 addresses need to be queried during lookup.

public static final int
IPV4_FIRST

Characteristic value signifying if IPv4 addresses should be returned first by InetAddressResolver.

public static final int
IPV6

Characteristic value signifying if IPv6 addresses need to be queried during lookup.

public static final int
IPV6_FIRST

Characteristic value signifying if IPv6 addresses should be returned first by InetAddressResolver.

Constructor Summary

AccessConstructor and Description
private
LookupPolicy(int characteristics)

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

a characteristics value
characteristics
()

Returns the set of characteristics of this lookup policy.

public static InetAddressResolver.LookupPolicy

Returns:

an instance of InetAddressResolver.LookupPolicy
of
(int
a value which represents the set of lookup characteristics
characteristics
)

This factory method creates a LookupPolicy instance with the given characteristics value.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

characteristicsback to summary
private final int characteristics
IPV4back to summary
public static final int IPV4

Characteristic value signifying if IPv4 addresses need to be queried during lookup.

Annotations
@Native
IPV4_FIRSTback to summary
public static final int IPV4_FIRST

Characteristic value signifying if IPv4 addresses should be returned first by InetAddressResolver.

Annotations
@Native
IPV6back to summary
public static final int IPV6

Characteristic value signifying if IPv6 addresses need to be queried during lookup.

Annotations
@Native
IPV6_FIRSTback to summary
public static final int IPV6_FIRST

Characteristic value signifying if IPv6 addresses should be returned first by InetAddressResolver.

Annotations
@Native

Constructor Detail

LookupPolicyback to summary
private LookupPolicy(int characteristics)

Method Detail

characteristicsback to summary
public int characteristics()

Returns the set of characteristics of this lookup policy.

Returns:int

a characteristics value

See Also
InetAddressResolver#lookupByName(String, LookupPolicy)
ofback to summary
public static InetAddressResolver.LookupPolicy of(int characteristics)

This factory method creates a LookupPolicy instance with the given characteristics value.

The characteristics value is an integer bit mask which defines parameters of a forward lookup operation. These parameters define at least:

  • the family type of the returned addresses
  • the order in which a resolver implementation should return its results

To request addresses of specific family types the following bit masks can be combined:


It is an error if neither LookupPolicy#IPV4 or LookupPolicy#IPV6 are set.

To request a specific ordering of the results:


If neither LookupPolicy#IPV4_FIRST or LookupPolicy#IPV6_FIRST are set it implies "system" order of addresses. It is an error to request both LookupPolicy#IPV4_FIRST and LookupPolicy#IPV6_FIRST.
Parameters
characteristics:int

a value which represents the set of lookup characteristics

Returns:InetAddressResolver.LookupPolicy

an instance of InetAddressResolver.LookupPolicy

Exceptions
IllegalArgumentException:
if an illegal characteristics bit mask is provided
See Also
InetAddressResolver#lookupByName(String, LookupPolicy)