本文整理汇总了Java中sun.net.util.IPAddressUtil.convertFromIPv4MappedAddress方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddressUtil.convertFromIPv4MappedAddress方法的具体用法?Java IPAddressUtil.convertFromIPv4MappedAddress怎么用?Java IPAddressUtil.convertFromIPv4MappedAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.net.util.IPAddressUtil
的用法示例。
在下文中一共展示了IPAddressUtil.convertFromIPv4MappedAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getByAddress
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* 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");
}
示例2: addrToString
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
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;
}
示例3: getByAddress
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* Create 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");
}
示例4: getByAddress
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* 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");
}