public class InetAddresses
extends java.lang.Object
| Constructor and Description |
|---|
InetAddresses() |
| Modifier and Type | Method and Description |
|---|---|
static java.net.InetAddress |
forString(java.lang.String ipString)
Returns the
InetAddress having the given string representation. |
static boolean |
isInetAddress(java.lang.String ipString) |
static java.lang.String |
toAddrString(java.net.InetAddress ip)
Returns the string representation of an
InetAddress. |
static java.lang.String |
toUriString(java.net.InetAddress ip)
Returns the string representation of an
InetAddress suitable
for inclusion in a URI. |
public static boolean isInetAddress(java.lang.String ipString)
public static java.lang.String toUriString(java.net.InetAddress ip)
InetAddress suitable
for inclusion in a URI.
For IPv4 addresses, this is identical to
InetAddress.getHostAddress(), but for IPv6 addresses it
compresses zeroes and surrounds the text with square brackets; for example
"[2001:db8::1]".
Per section 3.2.2 of
http://tools.ietf.org/html/rfc3986,
a URI containing an IPv6 string literal is of the form
"http://[2001:db8::1]:8888/index.html".
Use of either toAddrString(java.net.InetAddress),
InetAddress.getHostAddress(), or this method is recommended over
InetAddress.toString() when an IP address string literal is
desired. This is because InetAddress.toString() prints the
hostname and the IP address string joined by a "/".
ip - InetAddress to be converted to URI string literalString containing URI-safe string literalpublic static java.lang.String toAddrString(java.net.InetAddress ip)
InetAddress.
For IPv4 addresses, this is identical to
InetAddress.getHostAddress(), but for IPv6 addresses, the output
follows RFC 5952
section 4. The main difference is that this method uses "::" for zero
compression, while Java's version uses the uncompressed form.
This method uses hexadecimal for all IPv6 addresses, including IPv4-mapped IPv6 addresses such as "::c000:201". The output does not include a Scope ID.
ip - InetAddress to be converted to an address stringString containing the text-formatted IP addresspublic static java.net.InetAddress forString(java.lang.String ipString)
InetAddress having the given string representation.
This deliberately avoids all nameservice lookups (e.g. no DNS).
ipString - String containing an IPv4 or IPv6 string literal, e.g.
"192.168.0.1" or "2001:db8::1"InetAddress representing the argumentjava.lang.IllegalArgumentException - if the argument is not a valid IP string literal