title: Is this a good way to parse a ftp url scheme?
body: <p>I write a small java tool and a at the beginning I have to parse a url. I would like to know, what you are thinking about my solution and if there is a better way?
  Here are some examples:</p>
  <blockquote>
  <p>aaa://username:password@server:port/dir/</p>
  <p>aaa://server:port/dir/</p>
  <p>aaa://server:port</p>
  </blockquote>
  <p>Every kind of String is possible, if the user is not carefully. So it is possible, that my function get such a string</p>
  <blockquote>
  <p>aaa://username:pass</p>
  </blockquote>
  <p>too. But the string always starts witch aaa://.</p>
  <p>Here is my code:</p>
  <p>url = url.replaceFirst(&quot;aaa://&quot;, &quot;&quot;);</p>
  <pre><code>String params[] = url.split(&quot;@&quot;);
  if(params[0].compareTo(&quot;&quot;) != 0) {
      String paramsfst[] = params[0].split(&quot;:&quot;);
      if(params.length == 1) {
          if(paramsfst.length &gt;= 1) {
              this.server = parsePort(paramsfst[0]);
              if(paramsfst.length == 2) {
                  this.port = parsePort(paramsfst[1]);
              }
          }               
      } else {
          String paramssec[] = params[1].split(&quot;:&quot;);
          if(paramssec.length &gt;= 1) {
              this.server = parsePort(paramssec[0]);
              if(paramssec.length == 2) {
                  this.port = parsePort(paramssec[1]);
              }
          }
          if(paramsfst.length == 2) {
              this.username = paramsfst[0];
              this.password = paramsfst[1];   
          }
      }
      if(url.contains(&quot;/&quot;)) {
          this.path = url.substring(url.indexOf(&quot;/&quot;), url.length() -1);   
      }
  
  private String parsePort(String port) {
      int i = port.indexOf(&quot;/&quot;);
      if(i == -1) {
          return port;
      }
      return port.substring(0, i);
  }
  </code></pre>
  <p>What do you think?</p>