code: public String toExternalForm() {
  
      // pre-compute length of StringBuffer
      int len = this.getProtocol().length() + 1;
      if (this.getAuthority() != null && this.getAuthority().length() > 0) {
        len += 2 + this.getAuthority().length();
      }
      if (this.getPath() != null) {
        len += this.getPath().length();
      }
      if (this.getQuery() != null) {
        len += 1 + this.getQuery().length();
      }
      if (this.getRef() != null) {
        len += 1 + this.getRef().length();
      }
  
      final StringBuffer result = new StringBuffer(len);
      result.append(this.getProtocol());
      result.append(':');
      if (this.getAuthority() != null && this.getAuthority().length() > 0) {
        result.append("//");
        result.append(this.getAuthority());
      }
      if (this.getPath() != null) {
        result.append(this.getPath());
      }
      if (this.getQuery() != null) {
        result.append('?');
        result.append(this.getQuery());
      }
      if (this.getRef() != null) {
        result.append('#');
        result.append(this.getRef());
      }
      return result.toString();
    }
docs: Constructs a string representation of this <code>URL</code>. The string is created by calling
  the <code>toExternalForm</code> method of the stream protocol handler for this object.
  
  @return a string representation of this object.
  @see java.net.URL#URL(java.lang.String, java.lang.String, int, java.lang.String)
  @see java.net.URLStreamHandler#toExternalForm(java.net.URL)