Java Code Examples for sun.net.util.IPAddressUtil#convertFromIPv4MappedAddress()

The following examples show how to use sun.net.util.IPAddressUtil#convertFromIPv4MappedAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InetAddress.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 2
Source File: InetAddress.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public static InetAddress getByAddress(String host, byte[] addr, int scopeId)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr, scopeId);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 3
Source File: InetAddress.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "<code>java.sun.com</code>", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 4
Source File: InetAddress.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 5
Source File: InetAddress.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 6
Source File: InetAddress.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 7
Source File: InetAddress.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 8
Source File: InetAddress.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 9
Source File: InetAddress.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 10
Source File: InetAddress.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 11
Source File: InetAddress.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 12
Source File: InetAddress.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private  String addrToString(byte addr[]) {
  String stringifiedAddress = null;

    if (addr.length == Inet4Address.INADDRSZ) {
        stringifiedAddress = Inet4Address.numericToTextFormat(addr);
    } else { // treat as an IPV6 jobby
        byte[] newAddr
            = IPAddressUtil.convertFromIPv4MappedAddress(addr);
        if (newAddr != null) {
           stringifiedAddress = Inet4Address.numericToTextFormat(addr);
        } else {
            stringifiedAddress = Inet6Address.numericToTextFormat(addr);
        }
    }
    return stringifiedAddress;
}
 
Example 13
Source File: InetAddress.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code www.example.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @throws     UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && !host.isEmpty() && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 14
Source File: InetAddress.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
private  String addrToString(byte addr[]) {
  String stringifiedAddress = null;

    if (addr.length == Inet4Address.INADDRSZ) {
        stringifiedAddress = Inet4Address.numericToTextFormat(addr);
    } else { // treat as an IPV6 jobby
        byte[] newAddr
            = IPAddressUtil.convertFromIPv4MappedAddress(addr);
        if (newAddr != null) {
           stringifiedAddress = Inet4Address.numericToTextFormat(addr);
        } else {
            stringifiedAddress = Inet6Address.numericToTextFormat(addr);
        }
    }
    return stringifiedAddress;
}
 
Example 15
Source File: InetAddress.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 16
Source File: InetAddress.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 17
Source File: InetAddress.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 18
Source File: InetAddress.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 19
Source File: InetAddress.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}
 
Example 20
Source File: InetAddress.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an InetAddress based on the provided host name and IP address.
 * No name service is checked for the validity of the address.
 *
 * <p> The host name can either be a machine name, such as
 * "{@code java.sun.com}", or a textual representation of its IP
 * address.
 * <p> No validity checking is done on the host name either.
 *
 * <p> If addr specifies an IPv4 address an instance of Inet4Address
 * will be returned; otherwise, an instance of Inet6Address
 * will be returned.
 *
 * <p> IPv4 address byte array must be 4 bytes long and IPv6 byte array
 * must be 16 bytes long
 *
 * @param host the specified host
 * @param addr the raw IP address in network byte order
 * @return  an InetAddress object created from the raw IP address.
 * @exception  UnknownHostException  if IP address is of illegal length
 * @since 1.4
 */
public static InetAddress getByAddress(String host, byte[] addr)
    throws UnknownHostException {
    if (host != null && host.length() > 0 && host.charAt(0) == '[') {
        if (host.charAt(host.length()-1) == ']') {
            host = host.substring(1, host.length() -1);
        }
    }
    if (addr != null) {
        if (addr.length == Inet4Address.INADDRSZ) {
            return new Inet4Address(host, addr);
        } else if (addr.length == Inet6Address.INADDRSZ) {
            byte[] newAddr
                = IPAddressUtil.convertFromIPv4MappedAddress(addr);
            if (newAddr != null) {
                return new Inet4Address(host, newAddr);
            } else {
                return new Inet6Address(host, addr);
            }
        }
    }
    throw new UnknownHostException("addr is of illegal length");
}