Converts an address from its string representation to an IP address. The address can be either IPv4 or IPv6. @param addr The address, in string form @return The IP addresses @exception UnknownHostException The address is not a valid IP address.
(String addr)
| 314 | * @exception UnknownHostException The address is not a valid IP address. |
| 315 | */ |
| 316 | public static InetAddress |
| 317 | getByAddress(String addr) throws UnknownHostException { |
| 318 | byte [] bytes; |
| 319 | bytes = toByteArray(addr, IPv4); |
| 320 | if (bytes != null) |
| 321 | return InetAddress.getByAddress(addr, bytes); |
| 322 | bytes = toByteArray(addr, IPv6); |
| 323 | if (bytes != null) |
| 324 | return InetAddress.getByAddress(addr, bytes); |
| 325 | throw new UnknownHostException("Invalid address: " + addr); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Converts an address from its string representation to an IP address in |
no test coverage detected