Use Guava's int-toipv4 primitive
authorRobert Varga <[email protected]>
Fri, 12 Feb 2016 17:14:08 +0000 (18:14 +0100)
committerEd Warnicke <[email protected]>
Fri, 19 Feb 2016 21:04:06 +0000 (21:04 +0000)
Guava has a neat utility to perform the conversion, use that instead of
open-coding it.

Change-Id: Ifa8d79845950faccc3433b84e42dc2ba08828248
Signed-off-by: Robert Varga <[email protected]>
v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java

index 9eb9d3a..b4f3fe9 100644 (file)
@@ -16,6 +16,7 @@
 
 package io.fd.honeycomb.v3po.impl;
 
+import com.google.common.net.InetAddresses;
 import com.google.common.primitives.Ints;
 import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
@@ -168,15 +169,7 @@ public class V3poApiRequest extends V3poRequest {
     }
 
     private static String ipv4IntToString(final int ip) {
-        InetAddress addr = null;
-        byte[] bytes = Ints.toByteArray(ip);
-        try {
-            addr = InetAddress.getByAddress(bytes);
-        } catch (java.net.UnknownHostException e) {
-            e.printStackTrace();
-            return null;
-        }
-        return addr.getHostAddress();
+        return InetAddresses.fromInteger(ip).getHostAddress();
     }
 
     private Interface buildStateInterface(final int ifIndex,
@@ -197,7 +190,7 @@ public class V3poApiRequest extends V3poRequest {
                                           final int vtrTag1, final int vtrTag2,
                                           final Statistics stats) {
         InterfaceBuilder ifBuilder = new InterfaceBuilder();
-        java.lang.Class<? extends InterfaceType> ifType;
+        Class<? extends InterfaceType> ifType;
 
         // FIXME: missing types for virtualethernet, subinterface, tap interface etc
         if (interfaceName.startsWith("loop")) {