Package org.codelibs.fess.util
Class IpAddressUtil
java.lang.Object
org.codelibs.fess.util.IpAddressUtil
Utility class for handling IP addresses, particularly IPv6 addresses in URLs.
This class provides methods to properly format IPv6 addresses for use in URLs
by adding brackets where necessary.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilds a URL from protocol, hostname string, port, and path.static StringbuildUrl(String protocol, InetAddress address, int port, String path) Builds a URL from protocol, InetAddress, port, and path.protected static StringcompressIPv6(String ipv6Address) Compresses an IPv6 address string to its canonical compressed form.static StringformatForUrl(String address) Formats an IP address string for use in a URL.static StringgetUrlHost(InetAddress address) Generates a URL-safe host string from an InetAddress.static booleanisIPv6Address(String address) Determines if the given address string represents an IPv6 address.
-
Method Details
-
isIPv6Address
Determines if the given address string represents an IPv6 address. This method validates the address using InetAddress to ensure it's a valid IPv6 address.- Parameters:
address- the IP address string to check- Returns:
- true if the address is a valid IPv6 address, false otherwise
-
formatForUrl
Formats an IP address string for use in a URL. IPv6 addresses are wrapped in brackets, IPv4 addresses are returned as-is.- Parameters:
address- the IP address string to format- Returns:
- the formatted address (IPv6 with brackets, IPv4 unchanged)
-
compressIPv6
Compresses an IPv6 address string to its canonical compressed form. For example, "0:0:0:0:0:0:0:1" becomes "::1"- Parameters:
ipv6Address- the IPv6 address string to compress- Returns:
- the compressed IPv6 address string
-
getUrlHost
Generates a URL-safe host string from an InetAddress. For IPv6 addresses, this wraps the address in brackets and compresses it. For IPv4 addresses, returns the address as-is.- Parameters:
address- the InetAddress to format- Returns:
- the URL-safe host string
-
buildUrl
Builds a URL from protocol, InetAddress, port, and path. Properly handles IPv6 addresses by wrapping them in brackets.- Parameters:
protocol- the protocol (e.g., "http", "https")address- the InetAddress for the hostport- the port numberpath- the path (should start with "/" or be empty)- Returns:
- the complete URL string
-
buildUrl
Builds a URL from protocol, hostname string, port, and path. Properly handles IPv6 addresses by wrapping them in brackets if needed.- Parameters:
protocol- the protocol (e.g., "http", "https")host- the hostname or IP address stringport- the port numberpath- the path (should start with "/" or be empty)- Returns:
- the complete URL string
-