当前位置: 首页>>代码示例>>Java>>正文


Java IPAddressUtil.textToNumericFormatV6方法代码示例

本文整理汇总了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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:InetAddress.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Utils.java

示例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;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:34,代码来源:NetUtils.java

示例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");
    }
}
 
开发者ID:alibaba,项目名称:java-dns-cache-manipulator,代码行数:37,代码来源:IpParserUtil.java

示例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);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:6,代码来源:BufferTest.java


注:本文中的sun.net.util.IPAddressUtil.textToNumericFormatV6方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。