hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roland Weber <http-as...@dubioso.net>
Subject Re: java.net.URL or URI
Date Sat, 11 Mar 2006 09:20:02 GMT
Hi John,

> Pattern pat = new Pattern(someReallyCoolRegexHere);
> Matcher match = pat.matcher(webPageTextHere);
> while( match.find() )
>     GetMethod get = new GetMethod( new URL( topURL,
> match.group(1)).toString() );
> but if the url was supported, and extended with some of the simple
> features, it would be cleaner:
> GetMethod get = new GetMethod( topUrl, match.group(1) );
> As I type this I realize it is probably trivial, but surely a reason
> must exist that string was supported rather than url?

The URL class has 6 constructors in JDK 1.4.2 (I didn't bother to
check which ones were in the eralier JDK version which is the
prerequisite for HttpClient). Surely you don't expect us to duplicate
all of them just to save you a single line of code and two braces?

while( match.find() ) {
  URL from = new URL( topURL, match.group(1) );
  GetMethod get = new GetMethod( from.toString() );
  ... // I assume that something was omitted here, otherwise
      // you are pointlessly creating objects in a loop :-)

If you choose to make your code unreadable by nesting statements,
it is only fair that *you* should suffer the consequences.

The URI class was introduced with JDK 1.4. HttpClient requires only
an older JDK, I don't have in mind whether that was 1.2 or 1.3. But
the URI class also has a toString() method that can easily be used
in the way shown above. See how flexible the string constructor is?


To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org

View raw message