+ /**
+ * Parses the given {@code ip} and returns an {@link InetAddress} from it.
+ *
+ * @param ip
+ * The IP to parse
+ * @return The parsed inet address, or {@link Optional#absent()} if no inet
+ * address could be parsed
+ */
+ private Optional<InetAddress> parseInetAddress(String ip) {
+ Long ipNumber = Longs.tryParse(ip);
+ if (ipNumber == null) {
+ return Optional.absent();
+ }
+
+ StringBuilder hostname = new StringBuilder(15);
+ hostname.append((ipNumber >>> 24) & 0xff).append('.');
+ hostname.append((ipNumber >>> 16) & 0xff).append('.');
+ hostname.append((ipNumber >>> 8) & 0xff).append('.');
+ hostname.append(ipNumber & 0xff);
+ try {
+ return Optional.of(InetAddress.getByName(hostname.toString()));
+ } catch (UnknownHostException uhe1) {
+ return Optional.absent();
+ }
+ }
+