public String toSafeString(){
  String scheme=getScheme();
  String ssp=getSchemeSpecificPart();
  if (scheme != null) {
    if (scheme.equalsIgnoreCase("tel") || scheme.equalsIgnoreCase("sip") || scheme.equalsIgnoreCase("sms")|| scheme.equalsIgnoreCase("smsto")|| scheme.equalsIgnoreCase("mailto")) {
      StringBuilder builder=new StringBuilder(64);
      builder.append(scheme);
      builder.append(':');
      if (ssp != null) {
        for (int i=0; i < ssp.length(); i++) {
          char c=ssp.charAt(i);
          if (c == '-' || c == '@' || c == '.') {
            builder.append(c);
          }
 else {
            builder.append('x');
          }
        }
      }
      return builder.toString();
    }
 else     if (scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("ftp")) {
      ssp="//" + ((getHost() != null) ? getHost() : "") + ((getPort() != -1) ? (":" + getPort()) : "")+ "/...";
    }
  }
  StringBuilder builder=new StringBuilder(64);
  if (scheme != null) {
    builder.append(scheme);
    builder.append(':');
  }
  if (ssp != null) {
    builder.append(ssp);
  }
  return builder.toString();
}

public String toSafeString ( ) { String scheme = getScheme ( ) ; String ssp = getSchemeSpecificPart ( ) ; if ( scheme != null ) { if ( scheme . equalsIgnoreCase ( "tel" ) || scheme . equalsIgnoreCase ( "sip" ) || scheme . equalsIgnoreCase ( "sms" ) || scheme . equalsIgnoreCase ( "smsto" ) || scheme . equalsIgnoreCase ( "mailto" ) ) { StringBuilder builder = new StringBuilder ( 64 ) ; builder . append ( scheme ) ; builder . append ( ':' ) ; if ( ssp != null ) { for ( int i = 0 ; i < ssp . length ( ) ; i ++ ) { char c = ssp . charAt ( i ) ; if ( c == '-' || c == '@' || c == '.' ) { builder . append ( c ) ; } else { builder . append ( 'x' ) ; } } } return builder . toString ( ) ; } else if ( scheme . equalsIgnoreCase ( "http" ) || scheme . equalsIgnoreCase ( "https" ) || scheme . equalsIgnoreCase ( "ftp" ) ) { ssp = "//" + ( ( getHost ( ) != null ) ? getHost ( ) : "" ) + ( ( getPort ( ) != - 1 ) ? ( ":" + getPort ( ) ) : "" ) + "/..." ; } } StringBuilder builder = new StringBuilder ( 64 ) ; if ( scheme != null ) { builder . append ( scheme ) ; builder . append ( ':' ) ; } if ( ssp != null ) { builder . append ( ssp ) ; } return builder . toString ( ) ; }
return a string representation of the uri that is safe to print to logs and other places where pii should be avoided .
