use of org.minidns.dnslabel.DnsLabel in project minidns by MiniDNS.
the class DNSNameTest method getLabelsTest.
@Test
public void getLabelsTest() {
final String tldLabelString = "tld";
final String secondLevelString = "second-level-domain";
final String thirdLevelString = "third-level-domain";
final String dnsNameString = thirdLevelString + '.' + secondLevelString + '.' + tldLabelString;
final DNSName dnsName = DNSName.from(dnsNameString);
DNSLabel[] labels = dnsName.getLabels();
assertEquals(tldLabelString, labels[0].label);
assertEquals(secondLevelString, labels[1].label);
assertEquals(thirdLevelString, labels[2].label);
}
use of org.minidns.dnslabel.DnsLabel in project Smack by igniterealtime.
the class InternetAddress method from.
public static InternetAddress from(String address) {
final InternetAddress internetAddress;
if (InetAddressUtil.isIpV4Address(address)) {
internetAddress = new InternetAddress.Ipv4(address);
} else if (InetAddressUtil.isIpV6Address(address)) {
internetAddress = new InternetAddress.Ipv6(address);
} else if (address.contains(".")) {
InternetAddress domainNameInternetAddress;
try {
DnsName dnsName = DnsName.from(address);
domainNameInternetAddress = new InternetAddress.DomainName(address, dnsName);
} catch (InvalidDnsNameException e) {
domainNameInternetAddress = new InternetAddress.InvalidDomainName(address, e);
}
internetAddress = domainNameInternetAddress;
} else {
DnsLabel dnsLabel = DnsLabel.from(address);
internetAddress = new InternetAddress.DomainNameLabel(address, dnsLabel);
}
return internetAddress;
}