Is the class's comment "Currently this class supports only IPv4
addresses." still valid with the new changes?


On 7 September 2011 23:04,  <[email protected]> wrote:
> Author: olegk
> Date: Wed Sep  7 20:04:38 2011
> New Revision: 1166362
>
> URL: http://svn.apache.org/viewvc?rev=1166362&view=rev
> Log:
> Simplified InMemoryDnsResolver#add method
>
> Modified:
>    
> httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
>
> Modified: 
> httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
> URL: 
> http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java?rev=1166362&r1=1166361&r2=1166362&view=diff
> ==============================================================================
> --- 
> httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
>  (original)
> +++ 
> httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/InMemoryDnsResolver.java
>  Wed Sep  7 20:04:38 2011
> @@ -34,7 +34,6 @@ import java.util.concurrent.ConcurrentHa
>
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> -import org.apache.http.conn.util.InetAddressUtils;
>  import org.apache.http.conn.DnsResolver;
>
>  /**
> @@ -64,40 +63,23 @@ public class InMemoryDnsResolver impleme
>     }
>
>     /**
> -     * Associates the given IP address to the given host in this DNS 
> overrider.
> +     * Associates the given array of IP addresses to the given host in this 
> DNS overrider.
> +     * The IP addresses are assumed to be already resolved.
>      *
>      * @param host
>      *            The host name to be associated with the given IP.
> -     * @param ip
> -     *            IPv4 address to be resolved by this DNS overrider to the 
> given
> +     * @param ips
> +     *            array of IP addresses to be resolved by this DNS overrider 
> to the given
>      *            host name.
> -     *
> -     * @throws IllegalArgumentException
> -     *             if the given IP is not a valid IPv4 address or an 
> InetAddress
> -     *             instance cannot be built based on the given IPv4 address.
> -     *
> -     * @see InetAddress#getByAddress
>      */
> -    public void add(final String host, final String ip) {
> -        if (!InetAddressUtils.isIPv4Address(ip)) {
> -            throw new IllegalArgumentException(ip + " must be a valid IPv4 
> address");
> -        }
> -
> -        String[] ipParts = ip.split("\\.");
> -
> -        byte[] byteIpAddress = new byte[4];
> -
> -        for (int i = 0; i < 4; i++) {
> -            byteIpAddress[i] = Integer.decode(ipParts[i]).byteValue();
> +    public void add(final String host, final InetAddress... ips) {
> +        if (host == null) {
> +            throw new IllegalArgumentException("Host name may not be null");
>         }
> -
> -        try {
> -            dnsMap.put(host, new InetAddress[] { 
> InetAddress.getByAddress(byteIpAddress) });
> -        } catch (UnknownHostException e) {
> -            log.error("Unable to build InetAddress for " + ip, e);
> -            throw new IllegalArgumentException(e);
> +        if (ips == null) {
> +            throw new IllegalArgumentException("Array of IP addresses may 
> not be null");
>         }
> -
> +        dnsMap.put(host, ips);
>     }
>
>     /**
> @@ -108,11 +90,9 @@ public class InMemoryDnsResolver impleme
>         if (log.isInfoEnabled()) {
>             log.info("Resolving " + host + " to " + 
> Arrays.deepToString(resolvedAddresses));
>         }
> -
>         if(resolvedAddresses == null){
> -            throw new UnknownHostException(host + " cannot be resolved.");
> +            throw new UnknownHostException(host + " cannot be resolved");
>         }
> -
>         return resolvedAddresses;
>     }
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to