本文整理汇总了Java中com.google.common.net.InetAddresses.coerceToInteger方法的典型用法代码示例。如果您正苦于以下问题:Java InetAddresses.coerceToInteger方法的具体用法?Java InetAddresses.coerceToInteger怎么用?Java InetAddresses.coerceToInteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.net.InetAddresses
的用法示例。
在下文中一共展示了InetAddresses.coerceToInteger方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueFromrequestedObject
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
public String getValueFromrequestedObject(Object obj) {
if (obj instanceof BigInteger) {
return obj.toString();
} else if (obj instanceof Integer) {
return obj.toString();
} else if (obj instanceof Long) {
return obj.toString();
} else if (obj instanceof Date) {
Long tmp = ((Date) obj).getTime();
return tmp.toString();
} else if (obj instanceof InetAddress) {
Integer addr = InetAddresses.coerceToInteger((InetAddress) obj);
return addr.toString();
} else {
log.warn("input value has something problems");
return null;
}
}
示例2: get
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
* Lookup GeoEntity for an InetAddress
* @param inetAddress The InetAddress to be resolved.
* @return A GeoEntity for an InetAddress
*/
@Override
public GeoEntity get(final InetAddress inetAddress) {
PreConditions.checkNull(inetAddress, "inetAddress must not be null");
GeoEntity result = null;
if(inetAddress instanceof Inet4Address){
final Integer startIpNum = InetAddresses.coerceToInteger(inetAddress);
return IPV4_REPOSITORY.floorEntry(startIpNum) == null ? null
: IPV4_REPOSITORY.floorEntry(startIpNum).getValue() ;
}
else{
final BigInteger startIpBigInt = IPUtils.ipv6ToBigInteger(inetAddress);
return IPV6_REPOSITORY.floorEntry(startIpBigInt) == null ? null
: IPV6_REPOSITORY.floorEntry(startIpBigInt).getValue();
}
}
示例3: save
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
* Save GeoEntity for an InetAddress
* @param geoAttributes The attributes to be saved . Contains the attributes that will be needed
* as key and value to be put inside the TreeMap.
*/
@Override
public void save(final GeoAttributes geoAttributes) {
PreConditions.checkNull(geoAttributes, "geoAttributes must not be null");
final InetAddress startInetAddress = geoAttributes.getStartInetAddress();
final InetAddress endInetAddress = geoAttributes.getEndInetAddress();
final GeoEntity geoEntity = geoAttributes.getGeoEntity();
if(startInetAddress instanceof Inet6Address
&& endInetAddress instanceof Inet6Address)
{
final BigInteger startIpBigInt = IPUtils.ipv6ToBigInteger(startInetAddress);
IPV6_REPOSITORY.put(startIpBigInt,geoEntity);
}
else if (startInetAddress instanceof Inet4Address
&& endInetAddress instanceof Inet4Address)
{
final Integer startIpNum = InetAddresses.coerceToInteger(startInetAddress);
IPV4_REPOSITORY.put(startIpNum,geoEntity);
}
else{
//Well, this case should never happen. Maybe I'll throw in an exception later.
logger.warn("This shouldn't ever happen");
}
}
示例4: createEgressClassifierTransportEgressRemoteFlow
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
public Flow createEgressClassifierTransportEgressRemoteFlow(NodeId nodeId, long nsp, long outport,
String firstHopIp) {
MatchBuilder match = OpenFlow13Utils.getNspMatch(nsp);
Long ipl = InetAddresses.coerceToInteger(InetAddresses.forString(firstHopIp)) & 0xffffffffL;
List<Action> actionList = new ArrayList<>();
actionList.add(OpenFlow13Utils.createActionNxLoadTunIpv4Dst(ipl, actionList.size()));
actionList.add(OpenFlow13Utils.createActionOutPort("output:" + outport, actionList.size()));
InstructionsBuilder isb = OpenFlow13Utils.wrapActionsIntoApplyActionsInstruction(actionList);
String flowIdStr = EGRESS_CLASSIFIER_TPORTEGRESS_FLOW_NAME + nodeId.getValue() + "_" + nsp;
return OpenFlow13Utils.createFlowBuilder(NwConstants.EGRESS_SFC_CLASSIFIER_EGRESS_TABLE,
EGRESS_CLASSIFIER_EGRESS_REMOTE_PRIORITY, EGRESS_CLASSIFIER_TPORTEGRESS_COOKIE,
EGRESS_CLASSIFIER_TPORTEGRESS_FLOW_NAME, flowIdStr, match, isb).build();
}
示例5: getBroadcastAddressFromCidr
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
public static String getBroadcastAddressFromCidr(String cidr) {
String[] ipaddressValues = cidr.split("/");
int address = InetAddresses.coerceToInteger(InetAddresses.forString(ipaddressValues[0]));
int cidrPart = Integer.parseInt(ipaddressValues[1]);
int netmask = 0;
for (int j = 0; j < cidrPart; ++j) {
netmask |= 1 << 31 - j;
}
int network = address & netmask;
int broadcast = network | ~netmask;
return InetAddresses.toAddrString(InetAddresses.fromInteger(broadcast));
}
示例6: checkActionLoadTunIpv4
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
private void checkActionLoadTunIpv4(Action action, String ip) {
long ipl = InetAddresses.coerceToInteger(InetAddresses.forString(ip)) & 0xffffffffL;
NxActionRegLoadNodesNodeTableFlowApplyActionsCase regLoad =
(NxActionRegLoadNodesNodeTableFlowApplyActionsCase) action.getAction();
DstNxTunIpv4DstCase tunDstTypeCase = (DstNxTunIpv4DstCase) regLoad.getNxRegLoad().getDst().getDstChoice();
assertTrue(tunDstTypeCase.isNxTunIpv4Dst());
assertEquals(regLoad.getNxRegLoad().getValue().longValue(), ipl);
}
示例7: parseIPv4ToAthenaValue
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
public static Integer parseIPv4ToAthenaValue(String ip) {
InetAddress addr = InetAddresses.forString(ip);
int address = InetAddresses.coerceToInteger(addr);
return address;
}
示例8: hashCode
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
@Override
public int hashCode() {
return InetAddresses.coerceToInteger(ip);
}
示例9: toInt
import com.google.common.net.InetAddresses; //导入方法依赖的package包/类
/**
* 从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);
}