Created
June 20, 2022 18:04
-
-
Save robd003/295e56a13ece64c3e51c03e75ff086be to your computer and use it in GitHub Desktop.
Get domain from hostname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.net.InternetDomainName; | |
import java.net.URL; | |
public final class URLFunction { | |
private static String getDomain(String url_input) { | |
if (url_input.length() == 0) { | |
return url_input; | |
} | |
URL url = new URL(url_input); | |
String host = url.getHost(); | |
InternetDomainName domain_name = InternetDomainName.from(host).topPrivateDomain(); | |
return new String(domain_name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment