MCPcopy Create free account
hub / github.com/apache/nutch / toUNICODE

Method toUNICODE

src/java/org/apache/nutch/util/URLUtil.java:431–462  ·  view source on GitHub ↗
(String url)

Source from the content-addressed store, hash-verified

429 }
430
431 public static String toUNICODE(String url) {
432 try {
433 URL u = new URL(url);
434 String host = u.getHost();
435 if (host == null || host.isEmpty()) {
436 // no host name => no punycoded domain name
437 // also do not add additional slashes for file: URLs (NUTCH-1880)
438 return url;
439 }
440 StringBuilder sb = new StringBuilder();
441 sb.append(u.getProtocol());
442 sb.append("://");
443 if (u.getUserInfo() != null) {
444 sb.append(u.getUserInfo());
445 sb.append('@');
446 }
447 sb.append(IDN.toUnicode(host));
448 if (u.getPort() != -1) {
449 sb.append(':');
450 sb.append(u.getPort());
451 }
452 sb.append(u.getFile()); // includes query
453 if (u.getRef() != null) {
454 sb.append('#');
455 sb.append(u.getRef());
456 }
457
458 return sb.toString();
459 } catch (Exception e) {
460 return null;
461 }
462 }
463
464 /** For testing */
465 public static void main(String[] args) {

Callers 2

testToUNICODEMethod · 0.95
testFileProtocolMethod · 0.95

Calls 6

getProtocolMethod · 0.80
getPortMethod · 0.80
getHostMethod · 0.45
isEmptyMethod · 0.45
appendMethod · 0.45
toStringMethod · 0.45

Tested by 2

testToUNICODEMethod · 0.76
testFileProtocolMethod · 0.76