| 411 | } |
| 412 | |
| 413 | public static String toASCII(String url) { |
| 414 | try { |
| 415 | URL u = new URL(url); |
| 416 | String host = u.getHost(); |
| 417 | if (host == null || host.isEmpty()) { |
| 418 | // no host name => no punycoded domain name |
| 419 | // also do not add additional slashes for file: URLs (NUTCH-1880) |
| 420 | return url; |
| 421 | } |
| 422 | URI p = new URI(u.getProtocol(), u.getUserInfo(), IDN.toASCII(host), |
| 423 | u.getPort(), u.getPath(), u.getQuery(), u.getRef()); |
| 424 | |
| 425 | return p.toString(); |
| 426 | } catch (Exception e) { |
| 427 | return null; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | public static String toUNICODE(String url) { |
| 432 | try { |