Code example for URI

Methods: normalize, resolve, toASCIIString

0
  } 
 
  public void setAndPersistClusterURL(URI u, SharedPreferences prefs) {
    boolean shouldPersist = (prefs != null) && (clusterURL == null);
 
    Log.d(LOG_TAG, "Setting cluster URL to " + u.toASCIIString() +
                   (shouldPersist ? ". Persisting." : ". Not persisting."));
    clusterURL = u;
    if (shouldPersist) {
      Editor edit = prefs.edit();
      edit.putString("clusterURL", clusterURL.toASCIIString());
      edit.commit();
    } 
  } 
 
  public void setClusterURL(URI u) {
    setClusterURL(u, this.getPrefs());
  } 
 
  public void setClusterURL(URI u, SharedPreferences prefs) {
    if (u == null) {
      Log.w(LOG_TAG, "Refusing to set cluster URL to null.");
      return; 
    } 
    URI uri = u.normalize();
    if (uri.toASCIIString().endsWith("/")) {
      setAndPersistClusterURL(u, prefs);
      return; 
    } 
    setAndPersistClusterURL(uri.resolve("/"), prefs);
    Log.i(LOG_TAG, "Set cluster URL to " + clusterURL.toASCIIString() + ", given input " + u.toASCIIString());
  } 
 
  public void setClusterURL(String url) throws URISyntaxException {
    this.setClusterURL(new URI(url));
  }