Tabnine Logo
InternetDomainName.toString
Code IndexAdd Tabnine to your IDE (free)

How to use
toString
method
in
com.google.common.net.InternetDomainName

Best Java code snippets using com.google.common.net.InternetDomainName.toString (Showing top 20 results out of 315)

origin: google/guava

public void testToString() {
 for (String inputName : SOMEWHERE_UNDER_PS) {
  InternetDomainName domain = InternetDomainName.from(inputName);
  /*
   * We would ordinarily use constants for the expected results, but
   * doing it by derivation allows us to reuse the test case definitions
   * used in other tests.
   */
  String expectedName = Ascii.toLowerCase(inputName);
  expectedName = expectedName.replaceAll("[\u3002\uFF0E\uFF61]", ".");
  if (expectedName.endsWith(".")) {
   expectedName = expectedName.substring(0, expectedName.length() - 1);
  }
  assertEquals(expectedName, domain.toString());
 }
}
origin: line/armeria

private static Endpoint create(String host, int port) {
  requireNonNull(host, "host");
  if (NetUtil.isValidIpV4Address(host)) {
    return new Endpoint(host, host, port, DEFAULT_WEIGHT, HostType.IPv4_ONLY);
  }
  if (NetUtil.isValidIpV6Address(host)) {
    final String ipV6Addr;
    if (host.charAt(0) == '[') {
      // Strip surrounding '[' and ']'.
      ipV6Addr = host.substring(1, host.length() - 1);
    } else {
      ipV6Addr = host;
    }
    return new Endpoint(ipV6Addr, ipV6Addr, port, DEFAULT_WEIGHT, HostType.IPv6_ONLY);
  }
  return new Endpoint(InternetDomainName.from(host).toString(),
            null, port, DEFAULT_WEIGHT, HostType.HOSTNAME_ONLY);
}
origin: google/guava

public void testRegistrySuffixMultipleUnders() {
 // PSL has both *.uk and *.sch.uk; the latter should win.
 // See http://code.google.com/p/guava-libraries/issues/detail?id=1176
 InternetDomainName domain = InternetDomainName.from("www.essex.sch.uk");
 assertTrue(domain.hasRegistrySuffix());
 assertEquals("essex.sch.uk", domain.registrySuffix().toString());
 assertEquals("www.essex.sch.uk", domain.topDomainUnderRegistrySuffix().toString());
}
origin: google/guava

public void testPublicSuffixMultipleUnders() {
 // PSL has both *.uk and *.sch.uk; the latter should win.
 // See http://code.google.com/p/guava-libraries/issues/detail?id=1176
 InternetDomainName domain = InternetDomainName.from("www.essex.sch.uk");
 assertTrue(domain.hasPublicSuffix());
 assertEquals("essex.sch.uk", domain.publicSuffix().toString());
 assertEquals("www.essex.sch.uk", domain.topPrivateDomain().toString());
}
origin: google/guava

return new HostSpecifier(domain.toString());
origin: google/guava

public void testParent() {
 assertEquals("com", InternetDomainName.from("google.com").parent().toString());
 assertEquals("uk", InternetDomainName.from("co.uk").parent().toString());
 assertEquals("google.com", InternetDomainName.from("www.google.com").parent().toString());
 try {
  InternetDomainName.from("com").parent();
  fail("'com' should throw ISE on .parent() call");
 } catch (IllegalStateException expected) {
 }
}
origin: google/guava

public void testParentChild() {
 InternetDomainName origin = InternetDomainName.from("foo.com");
 InternetDomainName parent = origin.parent();
 assertEquals("com", parent.toString());
 // These would throw an exception if leniency were not preserved during parent() and child()
 // calls.
 InternetDomainName child = parent.child(LOTS_OF_DELTAS);
 child.child(LOTS_OF_DELTAS);
}
origin: google/guava

public void testChild() {
 InternetDomainName domain = InternetDomainName.from("foo.com");
 assertEquals("www.foo.com", domain.child("www").toString());
 try {
  domain.child("www.");
  fail("www..google.com should have been invalid");
 } catch (IllegalArgumentException expected) {
 }
}
origin: Graylog2/graylog2-server

/**
 * Extract the domain name (without subdomain). The Guava {@link InternetDomainName} implementation
 * provides a method to correctly handle this (and handles special cases for TLDs with multiple
 * names. eg. for lb01.store.amazon.co.uk, only amazon.co.uk would be extracted).
 * It uses https://publicsuffix.org behind the scenes.
 * <p>
 * Some domains (eg. completely randomly defined PTR domains) are not considered to have a public
 * suffix according to Guava. For those, the only option is to manually extract the domain with
 * string operations. This should be a rare case.
 */
public static void parseReverseLookupDomain(PtrDnsAnswer.Builder dnsAnswerBuilder, String hostname) {
  dnsAnswerBuilder.fullDomain(hostname);
  final InternetDomainName internetDomainName = InternetDomainName.from(hostname);
  if (internetDomainName.hasPublicSuffix()) {
    // Use Guava to extract domain name.
    final InternetDomainName topDomainName = internetDomainName.topDomainUnderRegistrySuffix();
    dnsAnswerBuilder.domain(topDomainName.toString());
  } else {
    /* Manually extract domain name.
     * Eg. for hostname test.some-domain.com, only some-domain.com will be extracted. */
    String[] split = hostname.split("\\.");
    if (split.length > 1) {
      dnsAnswerBuilder.domain(split[split.length - 2] + "." + split[split.length - 1]);
    } else if (split.length == 1) {
      dnsAnswerBuilder.domain(hostname); // Domain is a single word with no dots.
    } else {
      dnsAnswerBuilder.domain(""); // Domain is blank.
    }
  }
}
origin: google/j2objc

return new HostSpecifier(domain.toString());
origin: wildfly/wildfly

return new HostSpecifier(domain.toString());
origin: google/guava

public void testRegistrySuffixExclusion() {
 InternetDomainName domain = InternetDomainName.from("foo.city.yokohama.jp");
 assertTrue(domain.hasRegistrySuffix());
 assertEquals("yokohama.jp", domain.registrySuffix().toString());
 // Behold the weirdness!
 assertFalse(domain.registrySuffix().isRegistrySuffix());
}
origin: google/guava

public void testPublicSuffixExclusion() {
 InternetDomainName domain = InternetDomainName.from("foo.city.yokohama.jp");
 assertTrue(domain.hasPublicSuffix());
 assertEquals("yokohama.jp", domain.publicSuffix().toString());
 // Behold the weirdness!
 assertFalse(domain.publicSuffix().isPublicSuffix());
}
origin: internetarchive/heritrix3

/**
 * Adds outlinks to whois:{domain} and whois:{ipAddress} 
 */
protected void addWhoisLinks(CrawlURI curi) throws InterruptedException {
  CrawlHost ch = serverCache.getHostFor(curi.getUURI());
  if (ch == null) {
    return;
  }
  if (ch.getIP() != null) {
    // do a whois lookup on the ip address
    addWhoisLink(curi, ch.getIP().getHostAddress());
  }
  if (InternetDomainName.isValid(ch.getHostName())) {
    // do a whois lookup on the domain
    try {
      String topmostAssigned = InternetDomainName.from(ch.getHostName()).topPrivateDomain().toString();
      addWhoisLink(curi, topmostAssigned);
    } catch (IllegalStateException e) {
      // java.lang.IllegalStateException: Not under a public suffix: mod.uk
      logger.warning("problem resolving topmost assigned domain, will try whois lookup on the plain hostname " + ch.getHostName() + " - " + e);
      addWhoisLink(curi, ch.getHostName());
    }
  }
}

origin: internetarchive/heritrix3

/**
 * Returns a {@link LimitedCookieStoreFacade} whose
 * {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies
 * from {@code host} and its parent domains, if applicable.
 */
public CookieStore cookieStoreFor(String host) {
  CompositeCollection cookieCollection = new CompositeCollection();
  if (InternetDomainName.isValid(host)) {
    InternetDomainName domain = InternetDomainName.from(host);
    while (domain != null) {
      Collection<Cookie> subset = hostSubset(domain.toString());
      cookieCollection.addComposited(subset);
      if (domain.hasParent()) {
        domain = domain.parent();
      } else {
        domain = null;
      }
    }
  } else {
    Collection<Cookie> subset = hostSubset(host.toString());
    cookieCollection.addComposited(subset);
  }
  @SuppressWarnings("unchecked")
  List<Cookie> cookieList = new RestrictedCollectionWrappedList<Cookie>(cookieCollection);
  LimitedCookieStoreFacade store = new LimitedCookieStoreFacade(cookieList);
  return store;
}
origin: apache/metron

String ret = idn.publicSuffix().toString();
if(ret.startsWith("InternetDomainName")) {
 return Joiner.on(".").join(idn.publicSuffix().parts());
origin: com.ning.billing/killbill-osgi-bundles-jruby

/**
 * A deprecated synonym for {@link #toString()}.
 *
 * @deprecated Use {@link #toString()}
 */
@Deprecated
public String name() {
 return toString();
}
origin: at.bestsolution.efxclipse.eclipse/com.google.guava

/**
 * A deprecated synonym for {@link #toString()}.
 *
 * @deprecated Use {@link #toString()}
 */
@Deprecated
public String name() {
 return toString();
}
origin: googlesamples/android-AutofillFramework

public static String getCanonicalDomain(String domain) {
  InternetDomainName idn = InternetDomainName.from(domain);
  while (idn != null && !idn.isTopPrivateDomain()) {
    idn = idn.parent();
  }
  return idn == null ? null : idn.toString();
}
origin: com.google.guava/guava-tests

public void testChild() {
 InternetDomainName domain = InternetDomainName.from("foo.com");
 assertEquals("www.foo.com", domain.child("www").toString());
 try {
  domain.child("www.");
  fail("www..google.com should have been invalid");
 } catch (IllegalArgumentException expected) {
 }
}
com.google.common.netInternetDomainNametoString

Javadoc

Returns the domain name, normalized to all lower case.

Popular methods of InternetDomainName

  • from
    Returns an instance of InternetDomainName after lenient validation. Specifically, validation against
  • hasPublicSuffix
    Indicates whether this domain name ends in a #isPublicSuffix(), including if it is a public suffix i
  • isValid
    Indicates whether the argument is a syntactically valid domain name using lenient validation. Specif
  • isUnderPublicSuffix
    Indicates whether this domain name ends in a #isPublicSuffix(), while not being a public suffix itse
  • isTopPrivateDomain
    Indicates whether this domain name is composed of exactly one subdomain component followed by a #isP
  • hasParent
    Indicates whether this domain is composed of two or more parts.
  • <init>
    Private constructor used to implement #ancestor(int). Argument parts are assumed to be valid, as the
  • ancestor
    Returns the ancestor of the current domain at the given number of levels "higher" (rightward) in the
  • validatePart
    Helper method for #validateSyntax(List). Validates that one part of a domain name is valid.
  • validateSyntax
    Validation method used by to ensure that the domain name is syntactically valid according to RFC 103
  • topPrivateDomain
    Returns the portion of this domain name that is one level beneath the public suffix. For example, fo
  • name
    Returns the domain name, normalized to all lower case.
  • topPrivateDomain,
  • name,
  • findPublicSuffix,
  • matchesWildcardPublicSuffix,
  • parts,
  • child,
  • hasRegistrySuffix,
  • isTopDomainUnderRegistrySuffix,
  • isUnderRegistrySuffix

Popular in Java

  • Making http post requests using okhttp
  • setContentView (Activity)
  • scheduleAtFixedRate (Timer)
  • findViewById (Activity)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Permission (java.security)
    Legacy security code; do not use.
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • JFrame (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now