All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.vespa.net.InetAddressUtil Maven / Gradle / Ivy

Go to download

Library for use in Java components of Vespa. Shared code which do not fit anywhere else.

There is a newer version: 8.441.21
Show newest version
package ai.vespa.net;

import com.google.common.net.InetAddresses;

import java.net.Inet6Address;
import java.net.InetAddress;

/**
 * @author hakonhall
 */
public class InetAddressUtil {
    private InetAddressUtil() {}

    /** Returns the lower case string representation of the IP address (w/o scope), with :: compression for IPv6. */
    public static String toString(InetAddress inetAddress) {
        if (inetAddress instanceof Inet6Address) {
            String address = InetAddresses.toAddrString(inetAddress);
            // toAddrString() returns any interface/scope as a %-suffix,
            // see https://github.com/google/guava/commit/3f61870ac6e5b18dbb74ce6f6cb2930ad8750a43
            int percentIndex = address.indexOf('%');
            return percentIndex < 0 ? address : address.substring(0, percentIndex);
        } else {
            return inetAddress.getHostAddress();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy