Example usage for com.google.common.net InetAddresses forUriString

List of usage examples for com.google.common.net InetAddresses forUriString

Introduction

In this page you can find the example usage for com.google.common.net InetAddresses forUriString.

Prototype

public static InetAddress forUriString(String hostAddr) 

Source Link

Document

Returns an InetAddress representing the literal IPv4 or IPv6 host portion of a URL, encoded in the format specified by RFC 3986 section 3.2.2.

Usage

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);
}