Class Record<D extends Data>


  • public final class Record<D extends Data>
    extends java.lang.Object
    A generic DNS record.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Record.CLASS
      The symbolic class of a DNS record (usually Record.CLASS.IN for Internet).
      static class  Record.TYPE
      The resource record type.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      Record.CLASS clazz
      The record class (usually CLASS.IN).
      int clazzValue
      The value of the class field of a RR.
      DnsName name
      The generic name of this record.
      D payloadData
      The payload object of this record.
      long ttl
      The ttl of this record.
      Record.TYPE type
      The type (and payload type) of this record.
      boolean unicastQuery
      MDNS defines the highest bit of the class as the unicast query bit.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <E extends Data>
      Record<E>
      as​(java.lang.Class<E> dataClass)
      Return the record as record with the given Data class.
      boolean equals​(java.lang.Object other)  
      static <E extends Data>
      java.util.List<Record<E>>
      filter​(java.lang.Class<E> dataClass, java.util.Collection<Record<? extends Data>> input)  
      static <E extends Data>
      void
      filter​(java.util.Collection<Record<E>> result, java.lang.Class<E> dataClass, java.util.Collection<Record<? extends Data>> input)  
      D getPayload()
      The payload data, usually a subclass of data (A, AAAA, CNAME, ...).
      Question getQuestion()
      Get the question asking for this resource record.
      DnsMessage.Builder getQuestionMessage()  
      long getTtl()
      Retrieve the record ttl.
      int hashCode()  
      <E extends Data>
      Record<E>
      ifPossibleAs​(java.lang.Class<E> dataClass)
      Return the record if possible as record with the given Data class.
      boolean isAnswer​(Question q)
      Check if this record answers a given query.
      boolean isUnicastQuery()
      See if this query/response was a unicast query (highest class bit set).
      static Record<Data> parse​(java.io.DataInputStream dis, byte[] data)
      Parse a given record based on the full message data and the current stream position.
      byte[] toByteArray()  
      void toOutputStream​(java.io.OutputStream outputStream)  
      java.lang.String toString()
      Retrieve a textual representation of this resource record.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • name

        public final DnsName name
        The generic name of this record.
      • type

        public final Record.TYPE type
        The type (and payload type) of this record.
      • clazzValue

        public final int clazzValue
        The value of the class field of a RR. According to RFC 2671 (OPT RR) this is not necessarily representable using clazz field and unicastQuery bit
      • ttl

        public final long ttl
        The ttl of this record.
      • payloadData

        public final D extends Data payloadData
        The payload object of this record.
      • unicastQuery

        public final boolean unicastQuery
        MDNS defines the highest bit of the class as the unicast query bit.
    • Method Detail

      • parse

        public static Record<Dataparse​(java.io.DataInputStream dis,
                                         byte[] data)
                                  throws java.io.IOException
        Parse a given record based on the full message data and the current stream position.
        Parameters:
        dis - The DataInputStream positioned at the first record byte.
        data - The full message data.
        Returns:
        the record which was parsed.
        Throws:
        java.io.IOException - In case of malformed replies.
      • toOutputStream

        public void toOutputStream​(java.io.OutputStream outputStream)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Retrieve a textual representation of this resource record.
        Overrides:
        toString in class java.lang.Object
        Returns:
        String
      • isAnswer

        public boolean isAnswer​(Question q)
        Check if this record answers a given query.
        Parameters:
        q - The query.
        Returns:
        True if this record is a valid answer.
      • isUnicastQuery

        public boolean isUnicastQuery()
        See if this query/response was a unicast query (highest class bit set).
        Returns:
        True if it is a unicast query/response record.
      • getPayload

        public D getPayload()
        The payload data, usually a subclass of data (A, AAAA, CNAME, ...).
        Returns:
        The payload data.
      • getTtl

        public long getTtl()
        Retrieve the record ttl.
        Returns:
        The record ttl.
      • getQuestion

        public Question getQuestion()
        Get the question asking for this resource record. This will return null if the record is not retrievable, i.e. Record.TYPE.OPT.
        Returns:
        the question for this resource record or null.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • ifPossibleAs

        public <E extends DataRecord<E> ifPossibleAs​(java.lang.Class<E> dataClass)
        Return the record if possible as record with the given Data class. If the record does not hold payload of the given data class type, then null will be returned.
        Type Parameters:
        E - a subtype of Data.
        Parameters:
        dataClass - a class of the Data type.
        Returns:
        the record with a specialized payload type or null.
        See Also:
        as(Class)
      • as

        public <E extends DataRecord<E> as​(java.lang.Class<E> dataClass)
        Return the record as record with the given Data class. If the record does not hold payload of the given data class type, then a IllegalArgumentException will be thrown.
        Type Parameters:
        E - a subtype of Data.
        Parameters:
        dataClass - a class of the Data type.
        Returns:
        the record with a specialized payload type.
        See Also:
        ifPossibleAs(Class)
      • filter

        public static <E extends Data> void filter​(java.util.Collection<Record<E>> result,
                                                   java.lang.Class<E> dataClass,
                                                   java.util.Collection<Record<? extends Data>> input)
      • filter

        public static <E extends Data> java.util.List<Record<E>> filter​(java.lang.Class<E> dataClass,
                                                                        java.util.Collection<Record<? extends Data>> input)