code: protected String toExternalForm(URL u) {
  
          // pre-compute length of StringBuffer
          int len = u.getProtocol().length() + 1;
          if (u.getAuthority() != null && u.getAuthority().length() > 0)
              len += 2 + u.getAuthority().length();
          if (u.getPath() != null) {
              len += u.getPath().length();
          }
          if (u.getQuery() != null) {
              len += 1 + u.getQuery().length();
          }
          if (u.getRef() != null)
              len += 1 + u.getRef().length();
  
          StringBuilder result = new StringBuilder(len);
          result.append(u.getProtocol());
          result.append(":");
          if (u.getAuthority() != null) {// ANDROID: && u.getAuthority().length() > 0) {
              result.append("//");
              result.append(u.getAuthority());
          }
          String fileAndQuery = u.getFile();
          if (fileAndQuery != null) {
              result.append(fileAndQuery);
          }
          if (u.getRef() != null) {
              result.append("#");
              result.append(u.getRef());
          }
          return result.toString();
      }
docs: Converts a {@code URL} of a specific protocol to a
  {@code String}.
  
  @param   u   the URL.
  @return  a string representation of the {@code URL} argument.