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


Java IPAddressUtil.textToNumericFormatV4方法代码示例

本文整理汇总了Java中sun.net.util.IPAddressUtil.textToNumericFormatV4方法的典型用法代码示例。如果您正苦于以下问题:Java IPAddressUtil.textToNumericFormatV4方法的具体用法?Java IPAddressUtil.textToNumericFormatV4怎么用?Java IPAddressUtil.textToNumericFormatV4使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sun.net.util.IPAddressUtil的用法示例。


在下文中一共展示了IPAddressUtil.textToNumericFormatV4方法的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: intOfIpV4

import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
public int intOfIpV4(String ip) {
	int result = 0;
	byte[] bytes = IPAddressUtil.textToNumericFormatV4(ip);
	if (bytes == null) {
		return result;
	}
	for (byte b : bytes) {
		result = result << 8 | (b & 0xFF);
	}
	return result;
}
 
开发者ID:bejondshao,项目名称:personal,代码行数:12,代码来源:IPConverter.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: internalIp

import sun.net.util.IPAddressUtil; //导入方法依赖的package包/类
/**判断IP是否为内网IP*/
public static boolean internalIp(String ip) {
	byte[] addr = IPAddressUtil.textToNumericFormatV4(ip);
	return internalIp(addr);
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:6,代码来源:DataUtil.java


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