Class DnsName

  • All Implemented Interfaces:, java.lang.CharSequence, java.lang.Comparable<DnsName>

    public final class DnsName
    extends java.lang.Object
    implements java.lang.CharSequence,, java.lang.Comparable<DnsName>
    A DNS name, also called "domain name". A DNS name consists of multiple 'labels' and is subject to certain restrictions (see for example RFC 3696 ยง 2.).

    Instances of this class can be created by using from(String).

    This class holds three representations of a DNS name: ACE, raw ACE and IDN. ACE (ASCII Compatible Encoding), which can be accessed via ace, represents mostly the data that got send over the wire. But since DNS names are case insensitive, the ACE value is normalized to lower case. You can use getRawAce() to get the raw ACE data that was received, which possibly includes upper case characters. The IDN (Internationalized Domain Name), that is the DNS name as it should be shown to the user, can be retrieved using asIdn().

    More information about Internationalized Domain Names can be found at:
    See Also:
    RFC 3696, Serialized Form
    • Method Detail

      • writeToStream

        public void writeToStream​( os)
      • getBytes

        public byte[] getBytes()
        Serialize a domain name under IDN rules.
        The binary domain name representation.
      • getRawAce

        public java.lang.String getRawAce()
      • asIdn

        public java.lang.String asIdn()
      • getDomainpart

        public java.lang.String getDomainpart()
        Domainpart in ACE representation.
        the domainpart in ACE representation.
      • getHostpart

        public java.lang.String getHostpart()
        Hostpart in ACE representation.
        the hostpart in ACE representation.
      • size

        public int size()
      • length

        public int length()
        Specified by:
        length in interface java.lang.CharSequence
      • charAt

        public char charAt​(int index)
        Specified by:
        charAt in interface java.lang.CharSequence
      • subSequence

        public java.lang.CharSequence subSequence​(int start,
                                                  int end)
        Specified by:
        subSequence in interface java.lang.CharSequence
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.lang.CharSequence
        toString in class java.lang.Object
      • from

        public static DnsName from​(java.lang.CharSequence name)
      • from

        public static DnsName from​(java.lang.String name)
      • from

        public static DnsName from​(DnsName child,
                                   DnsName parent)
        Create a DNS name by "concatenating" the child under the parent name. The child can also be seen as the "left" part of the resulting DNS name and the parent is the "right" part.

        For example using "" as child and "of.this.parent.example" as parent, will result in a DNS name: "".

        child - the child DNS name.
        parent - the parent DNS name.
        the resulting of DNS name.
      • from

        public static DnsName from​(java.lang.String[] parts)
      • parse

        public static DnsName parse​( dis,
                                    byte[] data)
        Parse a domain name starting at the current offset and moving the input stream pointer past this domain name (even if cross references occure).
        dis - The input stream.
        data - The raw data (for cross references).
        The domain name string.
        Throws: - Should never happen.
      • compareTo

        public int compareTo​(DnsName other)
        Specified by:
        compareTo in interface java.lang.Comparable<DnsName>
      • equals

        public boolean equals​(java.lang.Object other)
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        hashCode in class java.lang.Object
      • getLabels

        public DnsLabel[] getLabels()
        Get a copy of the labels of this DNS name. The resulting array will contain the labels in reverse order, that is, the top-level domain will be at res[0].
        an array of the labels in reverse order.
      • getRawLabels

        public DnsLabel[] getRawLabels()
        Get a copy of the raw labels of this DNS name. The resulting array will contain the labels in reverse order, that is, the top-level domain will be at res[0].
        an array of the raw labels in reverse order.
      • getParent

        public DnsName getParent()
        Return the parent of this DNS label. Will return the root label if this label itself is the root label (because there is no parent of root).

        For example:

        • "".getParent() == ""
        • ".".getParent() == "."
        the parent of this DNS label.