本文整理汇总了Java中sun.net.util.IPAddressUtil.textToNumericFormatV6方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddressUtil.textToNumericFormatV6方法的具体用法?Java IPAddressUtil.textToNumericFormatV6怎么用?Java IPAddressUtil.textToNumericFormatV6使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.net.util.IPAddressUtil
的用法示例。
在下文中一共展示了IPAddressUtil.textToNumericFormatV6方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createAddressByteArray
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
private byte [] createAddressByteArray(String addrStr) {
byte[] addrArray;
// check if IPV4 address - most likely
addrArray = IPAddressUtil.textToNumericFormatV4(addrStr);
if (addrArray == null) {
addrArray = IPAddressUtil.textToNumericFormatV6(addrStr);
}
return addrArray;
}
示例2: getServerName
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* If the address was created with a domain name, then return
* the domain name string. If created with a literal IP address
* then return null. We do this to avoid doing a reverse lookup
* Used to populate the TLS SNI parameter. So, SNI is only set
* when a domain name was supplied.
*/
public static String getServerName(InetSocketAddress addr) {
String host = addr.getHostString();
if (IPAddressUtil.textToNumericFormatV4(host) != null)
return null;
if (IPAddressUtil.textToNumericFormatV6(host) != null)
return null;
return host;
}
示例3: unresolvedHostToNormalizedString
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* Returns an address in a normalized format for Akka.
* When an IPv6 address is specified, it normalizes the IPv6 address to avoid
* complications with the exact URL match policy of Akka.
* @param host The hostname, IPv4 or IPv6 address
* @return host which will be normalized if it is an IPv6 address
*/
public static String unresolvedHostToNormalizedString(String host) {
// Return loopback interface address if host is null
// This represents the behavior of {@code InetAddress.getByName } and RFC 3330
if (host == null) {
host = InetAddress.getLoopbackAddress().getHostAddress();
} else {
host = host.trim().toLowerCase();
}
// normalize and valid address
if (IPAddressUtil.isIPv6LiteralAddress(host)) {
byte[] ipV6Address = IPAddressUtil.textToNumericFormatV6(host);
host = getIPv6UrlRepresentation(ipV6Address);
} else if (!IPAddressUtil.isIPv4LiteralAddress(host)) {
try {
// We don't allow these in hostnames
Preconditions.checkArgument(!host.startsWith("."));
Preconditions.checkArgument(!host.endsWith("."));
Preconditions.checkArgument(!host.contains(":"));
} catch (Exception e) {
throw new IllegalConfigurationException("The configured hostname is not valid", e);
}
}
return host;
}
示例4: ip2ByteArray
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**
* dig from InetAddress#getAllByName(java.lang.String, java.net.InetAddress)
*/
static byte[] ip2ByteArray(String ip) {
boolean ipv6Expected = false;
if (ip.charAt(0) == '[') {
// This is supposed to be an IPv6 literal
if (ip.length() > 2 && ip.charAt(ip.length() - 1) == ']') {
ip = ip.substring(1, ip.length() - 1);
ipv6Expected = true;
} else {
// This was supposed to be a IPv6 address, but it's not!
throw new IllegalArgumentException(ip + ": invalid IPv6 address");
}
}
if (Character.digit(ip.charAt(0), 16) != -1 || (ip.charAt(0) == ':')) {
// see if it is IPv4 address
byte[] address = IPAddressUtil.textToNumericFormatV4(ip);
if (address != null) return address;
// see if it is IPv6 address
// Check if a numeric or string zone id is present
address = IPAddressUtil.textToNumericFormatV6(ip);
if (address != null) return address;
if (ipv6Expected) {
throw new IllegalArgumentException(ip + ": invalid IPv6 address");
} else {
throw new IllegalArgumentException(ip + ": invalid IP address");
}
} else {
throw new IllegalArgumentException(ip + ": invalid IP address");
}
}
示例5: writeIpV6
import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
static String writeIpV6(String address) {
byte[] ipv6 = IPAddressUtil.textToNumericFormatV6(address);
byte[] buffered = new Buffer(Buffer.ipv6SizeInBytes(ipv6)).writeIpV6(ipv6).toByteArray();
return new String(buffered, UTF_8);
}