< prev index next >
src/java.base/share/classes/java/net/InetSocketAddress.java
Print this page
*** 99,113 ****
return addr == null;
}
@Override
public String toString() {
if (isUnresolved()) {
! return hostname + ":" + port;
} else {
! return addr.toString() + ":" + port;
}
}
@Override
public final boolean equals(Object obj) {
if (obj == null || !(obj instanceof InetSocketAddressHolder))
--- 99,122 ----
return addr == null;
}
@Override
public String toString() {
+
+ String formatted;
+
if (isUnresolved()) {
! formatted = hostname + "/<unresolved>";
} else {
! formatted = addr.toString();
! if (addr instanceof Inet6Address) {
! int i = formatted.lastIndexOf("/");
! formatted = formatted.substring(0, i + 1)
! + "[" + formatted.substring(i + 1) + "]";
! }
}
+ return formatted + ":" + port;
}
@Override
public final boolean equals(Object obj) {
if (obj == null || !(obj instanceof InetSocketAddressHolder))
*** 365,375 ****
/**
* Constructs a string representation of this InetSocketAddress.
* This String is constructed by calling toString() on the InetAddress
* and concatenating the port number (with a colon). If the address
! * is unresolved then the part before the colon will only contain the hostname.
*
* @return a string representation of this object.
*/
@Override
public String toString() {
--- 374,386 ----
/**
* Constructs a string representation of this InetSocketAddress.
* This String is constructed by calling toString() on the InetAddress
* and concatenating the port number (with a colon). If the address
! * is an IPv6 address, the IPv6 literal is enclosed in square brackets.
! * If the address is {@linkplain #isUnresolved() unresolved},
! * {@code <unresolved>} is displayed in place of the address literal.
*
* @return a string representation of this object.
*/
@Override
public String toString() {
< prev index next >