Java Code Examples for com.google.common.net.InetAddresses#coerceToInteger()

The following examples show how to use com.google.common.net.InetAddresses#coerceToInteger() . 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: ChannelUtils.java    From bistoury with GNU General Public License v3.0 4 votes vote down vote up
public static int inetAtoN(String ip) {
    if (ip.equalsIgnoreCase(LOCALHOST)) return LOCALHOST_IP;
    return InetAddresses.coerceToInteger(InetAddresses.forString(ip));
}
 
Example 2
Source File: CidrAddressBlock.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public int hashCode() {
  return InetAddresses.coerceToInteger(ip);
}
 
Example 3
Source File: TestGeolocationProcessor.java    From datacollector with Apache License 2.0 4 votes vote down vote up
private static int ipAsStringToInt(String s) {
  return InetAddresses.coerceToInteger(InetAddresses.forString(s));
}
 
Example 4
Source File: RouterId.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
RouterId(final PeerId peerId) {
    this.peerId = requireNonNull(peerId);
    // This relies on peedId being initialized
    this.intBits = InetAddresses.coerceToInteger(InetAddresses.forString(toString()));
}
 
Example 5
Source File: StrictBGPPeerRegistry.java    From bgpcep with Eclipse Public License 1.0 4 votes vote down vote up
private static long toLong(final Ipv4Address from) {
    final int i = InetAddresses.coerceToInteger(InetAddresses.forString(from.getValue()));
    return UnsignedInts.toLong(i);
}
 
Example 6
Source File: AwsNetworkService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private boolean isInRange(String address, SubnetInfo subnetInfo) {
    int low = InetAddresses.coerceToInteger(InetAddresses.forString(subnetInfo.getLowAddress()));
    int high = InetAddresses.coerceToInteger(InetAddresses.forString(subnetInfo.getHighAddress()));
    int currentAddress = InetAddresses.coerceToInteger(InetAddresses.forString(address));
    return low <= currentAddress && currentAddress <= high;
}
 
Example 7
Source File: AwsNetworkService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private String incrementIp(String ip) {
    int ipValue = InetAddresses.coerceToInteger(InetAddresses.forString(ip)) + INCREMENT_HOST_NUM;
    return InetAddresses.fromInteger(ipValue).getHostAddress();
}
 
Example 8
Source File: AwsNetworkService.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private String toSubnetCidr(String ip) {
    int ipValue = InetAddresses.coerceToInteger(InetAddresses.forString(ip)) - 1;
    return InetAddresses.fromInteger(ipValue).getHostAddress() + "/24";
}
 
Example 9
Source File: AwsNetworkServiceTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private String incrementIp(String ip) {
    int ipValue = InetAddresses.coerceToInteger(InetAddresses.forString(ip)) + 256;
    return InetAddresses.fromInteger(ipValue).getHostAddress();
}
 
Example 10
Source File: DefaultSubnetCidrProvider.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private boolean isInRange(String address, SubnetUtils.SubnetInfo subnetInfo) {
    int low = InetAddresses.coerceToInteger(InetAddresses.forString(subnetInfo.getLowAddress()));
    int high = InetAddresses.coerceToInteger(InetAddresses.forString(subnetInfo.getHighAddress()));
    int currentAddress = InetAddresses.coerceToInteger(InetAddresses.forString(address));
    return low <= currentAddress && currentAddress <= high;
}
 
Example 11
Source File: DefaultSubnetCidrProvider.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private String incrementIp(String ip) {
    int ipValue = InetAddresses.coerceToInteger(InetAddresses.forString(ip)) + INCREMENT_HOST_NUM;
    return InetAddresses.fromInteger(ipValue).getHostAddress();
}
 
Example 12
Source File: DefaultSubnetCidrProvider.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private String toSubnetCidr(String ip) {
    int ipValue = InetAddresses.coerceToInteger(InetAddresses.forString(ip)) - 1;
    return InetAddresses.fromInteger(ipValue).getHostAddress() + "/24";
}
 
Example 13
Source File: IPUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 从InetAddress转化到int, 传输和存储时, 用int代表InetAddress是最小的开销.
 * 
 * InetAddress可以是IPV4或IPV6,都会转成IPV4.
 * 
 * @see com.google.common.net.InetAddresses#coerceToInteger(InetAddress)
 */
public static int toInt(InetAddress address) {
	return InetAddresses.coerceToInteger(address);
}
 
Example 14
Source File: IPUtil.java    From vjtools with Apache License 2.0 2 votes vote down vote up
/**
 * 从InetAddress转化到int, 传输和存储时, 用int代表InetAddress是最小的开销.
 * 
 * InetAddress可以是IPV4或IPV6,都会转成IPV4.
 * 
 * @see com.google.common.net.InetAddresses#coerceToInteger(InetAddress)
 */
public static int toInt(InetAddress address) {
	return InetAddresses.coerceToInteger(address);
}
 
Example 15
Source File: IPUtil.java    From j360-dubbo-app-all with Apache License 2.0 2 votes vote down vote up
/**
 * 从InetAddress转化到int, 传输和存储时, 用int代表InetAddress是最小的开销.
 * 
 * InetAddress可以是IPV4或IPV6,都会转成IPV4.
 * 
 * @see com.google.common.net.InetAddresses#coerceToInteger(InetAddress)
 */
public static int toInt(InetAddress address) {
	return InetAddresses.coerceToInteger(address);
}