Class DnsName

    • Method Detail

      • writeToStream

        public void writeToStream​(java.io.OutputStream os)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • getBytes

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

        public java.lang.String getAce()
        Return the ACE (ASCII Compatible Encoding) version of this DNS name. Note that this method may return a String containing null bytes. Those Strings are notoriously difficult to handle from a security perspective. Therefore it is recommended to use toString() instead, which will return a sanitized String.
        Returns:
        the ACE version of this DNS name.
        Since:
        1.1.0
      • getRawAce

        public java.lang.String getRawAce()
        Returns the raw ACE version of this DNS name. That is, the version as it was received over the wire. Most notably, this version may include uppercase letters. Please refer to getAce() for a discussion of the security implications when working with the ACE representation of a DNS name.
        Returns:
        the raw ACE version of this DNS name.
        See Also:
        getAce()
      • asIdn

        public java.lang.String asIdn()
      • getDomainpart

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

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

        public int size()
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.lang.CharSequence
        Overrides:
        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 "i.am.the.child" as child and "of.this.parent.example" as parent, will result in a DNS name: "i.am.the.child.of.this.parent.example".

        Parameters:
        child - the child DNS name.
        parent - the parent DNS name.
        Returns:
        the resulting of DNS name.
      • from

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

        public static DnsName parse​(java.io.DataInputStream dis,
                                    byte[] data)
                             throws java.io.IOException
        Parse a domain name starting at the current offset and moving the input stream pointer past this domain name (even if cross references occure).
        Parameters:
        dis - The input stream.
        data - The raw data (for cross references).
        Returns:
        The domain name string.
        Throws:
        java.io.IOException - 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)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        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].
        Returns:
        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].
        Returns:
        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:

        • "foo.bar.org".getParent() == "bar.org"
        • ".".getParent() == "."
        Returns:
        the parent of this DNS label.