List of usage examples for com.google.common.net InetAddresses forUriString
public static InetAddress forUriString(String hostAddr)
From source file:fr.letroll.ttorrentandroid.common.protocol.http.HTTPAnnounceRequestMessage.java
@VisibleForTesting @Nonnull//from ww w .ja v a 2 s . c o m /* pp */ static InetSocketAddress toInetSocketAddress(@Nonnull String sockstr, int port) { if (sockstr.indexOf(':') == -1) return new InetSocketAddress(InetAddresses.forString(sockstr), port); if (sockstr.startsWith("[")) { int idx = sockstr.indexOf("]:"); if (idx == -1) // Pure bracket-surrounded IPv6 address. return new InetSocketAddress(InetAddresses.forUriString(sockstr), port); int port6 = Integer.parseInt(sockstr.substring(idx + 2)); return new InetSocketAddress(InetAddresses.forUriString(sockstr.substring(0, idx + 1)), port6); } int idx = sockstr.indexOf(':'); if (idx != -1) { // IPv4 plus port int port4 = Integer.parseInt(sockstr.substring(idx + 1)); return new InetSocketAddress(InetAddresses.forUriString(sockstr.substring(0, idx)), port4); } return new InetSocketAddress(InetAddresses.forUriString(sockstr.substring(0, idx)), port); }