446 results = resolve(ctx, ip6lit, ids, 0);
447 host = results.get(0);
448 }
449 }
450 } catch (Exception e) {
451 throw new UnknownHostException(e.getMessage());
452 }
453 // Either we couldn't find it or the address was neither IPv4 or IPv6
454 if (host == null)
455 throw new UnknownHostException();
456 // remove trailing dot
457 if (host.endsWith(".")) {
458 host = host.substring(0, host.length() - 1);
459 }
460 return host;
461 }
462
463
464 // ---------
465
466 private static void appendIfLiteralAddress(String addr, StringBuffer sb) {
467 if (IPAddressUtil.isIPv4LiteralAddress(addr)) {
468 sb.append("dns://" + addr + " ");
469 } else {
470 if (IPAddressUtil.isIPv6LiteralAddress(addr)) {
471 sb.append("dns://[" + addr + "] ");
472 }
473 }
474 }
475
476 /*
477 * @return String containing the JNDI-DNS provider URL
478 * corresponding to the supplied List of nameservers.
479 */
480 private static String createProviderURL(List<String> nsList) {
481 StringBuffer sb = new StringBuffer();
482 for (String s: nsList) {
483 appendIfLiteralAddress(s, sb);
484 }
485 return sb.toString();
486 }
487
488 /*
489 * @return String containing the JNDI-DNS provider URL
490 * corresponding to the list of nameservers
491 * contained in the provided str.
492 */
493 private static String createProviderURL(String str) {
494 StringBuffer sb = new StringBuffer();
495 StringTokenizer st = new StringTokenizer(str, ",");
496 while (st.hasMoreTokens()) {
497 appendIfLiteralAddress(st.nextToken(), sb);
498 }
499 return sb.toString();
500 }
501 }
|
446 results = resolve(ctx, ip6lit, ids, 0);
447 host = results.get(0);
448 }
449 }
450 } catch (Exception e) {
451 throw new UnknownHostException(e.getMessage());
452 }
453 // Either we couldn't find it or the address was neither IPv4 or IPv6
454 if (host == null)
455 throw new UnknownHostException();
456 // remove trailing dot
457 if (host.endsWith(".")) {
458 host = host.substring(0, host.length() - 1);
459 }
460 return host;
461 }
462
463
464 // ---------
465
466 private static void appendIfLiteralAddress(String addr, StringBuilder sb) {
467 if (IPAddressUtil.isIPv4LiteralAddress(addr)) {
468 sb.append("dns://").append(addr).append(' ');
469 } else {
470 if (IPAddressUtil.isIPv6LiteralAddress(addr)) {
471 sb.append("dns://[").append(addr).append("] ");
472 }
473 }
474 }
475
476 /*
477 * @return String containing the JNDI-DNS provider URL
478 * corresponding to the supplied List of nameservers.
479 */
480 private static String createProviderURL(List<String> nsList) {
481 StringBuilder sb = new StringBuilder();
482 for (String s: nsList) {
483 appendIfLiteralAddress(s, sb);
484 }
485 return sb.toString();
486 }
487
488 /*
489 * @return String containing the JNDI-DNS provider URL
490 * corresponding to the list of nameservers
491 * contained in the provided str.
492 */
493 private static String createProviderURL(String str) {
494 StringBuilder sb = new StringBuilder();
495 StringTokenizer st = new StringTokenizer(str, ",");
496 while (st.hasMoreTokens()) {
497 appendIfLiteralAddress(st.nextToken(), sb);
498 }
499 return sb.toString();
500 }
501 }
|