Search in sources :

Example 1 with DnsLabel

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);
}
Also used : DNSName(org.minidns.dnsname.DNSName) DNSLabel(org.minidns.dnslabel.DNSLabel) Test(org.junit.Test)

Example 2 with DnsLabel

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;
}
Also used : DnsName(org.minidns.dnsname.DnsName) DnsLabel(org.minidns.dnslabel.DnsLabel) InvalidDnsNameException(org.minidns.dnsname.InvalidDnsNameException)

Aggregations

Test (org.junit.Test)1 DNSLabel (org.minidns.dnslabel.DNSLabel)1 DnsLabel (org.minidns.dnslabel.DnsLabel)1 DNSName (org.minidns.dnsname.DNSName)1 DnsName (org.minidns.dnsname.DnsName)1 InvalidDnsNameException (org.minidns.dnsname.InvalidDnsNameException)1