code: public static InetAddress forUriString(String hostAddr) {
      Preconditions.checkNotNull(hostAddr);
  
      // Decide if this should be an IPv6 or IPv4 address.
      String ipString;
      int expectBytes;
      if (hostAddr.startsWith("[") && hostAddr.endsWith("]")) {
        ipString = hostAddr.substring(1, hostAddr.length() - 1);
        expectBytes = 16;
      } else {
        ipString = hostAddr;
        expectBytes = 4;
      }
  
      // Parse the address, and make sure the length/version is correct.
      byte[] addr = ipStringToBytes(ipString);
      if (addr == null || addr.length != expectBytes) {
        throw new IllegalArgumentException(
            String.format("Not a valid URI IP literal: '%s'", hostAddr));
      }
  
      return bytesToInetAddress(addr);
    }
docs: 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.
  
  <p>This function is similar to {@link InetAddresses#forString(String)},
  however, it requires that IPv6 addresses are surrounded by square brackets.
  
  <p>This function is the inverse of
  {@link InetAddresses#toUriString(java.net.InetAddress)}.
  
  @param hostAddr A RFC 3986 section 3.2.2 encoded IPv4 or IPv6 address
  @return an InetAddress representing the address in {@code hostAddr}
  @throws IllegalArgumentException if {@code hostAddr} is not a valid
  IPv4 address, or IPv6 address surrounded by square brackets