org.minidns.dnsmessage

## Class DnsMessage.Builder

- java.lang.Object
- - org.minidns.dnsmessage.DnsMessage.Builder

- Enclosing class:
    DnsMessage

      public static final class DnsMessage.Builder
      extends Object

  Builder class for constructing DNS messages.
  Provides a fluent API for building DNS messages with various sections and flags configured step by step.

- - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `DnsMessage.Builder` | `addAdditionalResourceRecord(Record<? extends Data> record)`
    `DnsMessage.Builder` | `addAdditionalResourceRecords(List<Record<? extends Data>> records)`
    `DnsMessage.Builder` | `addAnswer(Record<? extends Data> answer)`
    `DnsMessage.Builder` | `addAnswers(Collection<Record<? extends Data>> records)`
    `DnsMessage.Builder` | `addNameserverRecords(Record<? extends Data> record)`
    `DnsMessage.Builder` | `addQuestion(Question question)`
    `DnsMessage` | `build()`
    `void` | `copyFlagsFrom(DnsMessage dnsMessage)`
    `List<Record<? extends Data>>` | `getAdditionalResourceRecords()`
    `List<Record<? extends Data>>` | `getAnswers()`
    `Edns.Builder` | `getEdnsBuilder()` Get the @{link EDNS} builder.
    `DnsMessage.Builder` | `setAdditionalResourceRecords(Collection<Record<? extends Data>> records)`
    `DnsMessage.Builder` | `setAnswers(Collection<Record<? extends Data>> records)`
    `DnsMessage.Builder` | `setAuthenticData(boolean authenticData)` Set the authentic data flag on this DNS message.
    `DnsMessage.Builder` | `setAuthoritativeAnswer(boolean authoritativeAnswer)` Set the authoritative answer flag.
    `DnsMessage.Builder` | `setCheckDisabled(boolean checkingDisabled)` Deprecated.
    `DnsMessage.Builder` | `setCheckingDisabled(boolean checkingDisabled)` Change the check status of this packet.
    `DnsMessage.Builder` | `setId(int id)` Set the current DNS message id.
    `DnsMessage.Builder` | `setNameserverRecords(Collection<Record<? extends Data>> records)`
    `DnsMessage.Builder` | `setOpcode(DnsMessage.OPCODE opcode)`
    `DnsMessage.Builder` | `setQrFlag(boolean query)` Set the QR flag.
    `DnsMessage.Builder` | `setQuestion(Question question)` Set the question part of this message.
    `DnsMessage.Builder` | `setQuestions(List<Question> questions)` Set the question part of this message.
    `DnsMessage.Builder` | `setReceiveTimestamp(long receiveTimestamp)`
    `DnsMessage.Builder` | `setRecursionAvailable(boolean recursionAvailable)` Set the recursion available flog from this DNS message.
    `DnsMessage.Builder` | `setRecursionDesired(boolean recursionDesired)` Set the recursion desired flag on this message.
    `DnsMessage.Builder` | `setResponseCode(DnsMessage.RESPONSE_CODE responseCode)`
    `DnsMessage.Builder` | `setTruncated(boolean truncated)` Set the truncation bit on this DNS message.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Method Detail

    - #### addAdditionalResourceRecord

          public DnsMessage.Builder addAdditionalResourceRecord(Record<? extends Data> record)

    - #### addAdditionalResourceRecords

          public DnsMessage.Builder addAdditionalResourceRecords(List<Record<? extends Data>> records)

    - #### addAnswer

          public DnsMessage.Builder addAnswer(Record<? extends Data> answer)

    - #### addAnswers

          public DnsMessage.Builder addAnswers(Collection<Record<? extends Data>> records)

    - #### addNameserverRecords

          public DnsMessage.Builder addNameserverRecords(Record<? extends Data> record)

    - #### addQuestion

          public DnsMessage.Builder addQuestion(Question question)

    - #### build

          public DnsMessage build()

    - #### copyFlagsFrom

          public void copyFlagsFrom(DnsMessage dnsMessage)

    - #### getAdditionalResourceRecords

          public List<Record<? extends Data>> getAdditionalResourceRecords()

    - #### getAnswers

          public List<Record<? extends Data>> getAnswers()

    - #### getEdnsBuilder

          public Edns.Builder getEdnsBuilder()

      Get the @{link EDNS} builder. If no builder has been set so far, then a new one will be created.

      The EDNS record can be used to announce the supported size of UDP payload as well as additional flags.

      Note that some networks and firewalls are known to block big UDP payloads. 1280 should be a reasonable value, everything below 512 is treated as 512 and should work on all networks.

      Returns:
        a EDNS builder.

    - #### setAdditionalResourceRecords

          public DnsMessage.Builder setAdditionalResourceRecords(Collection<Record<? extends Data>> records)

    - #### setAnswers

          public DnsMessage.Builder setAnswers(Collection<Record<? extends Data>> records)

    - #### setAuthenticData

          public DnsMessage.Builder setAuthenticData(boolean authenticData)

      Set the authentic data flag on this DNS message.
      Parameters:
        `authenticData` - The new authentic data flag value.
      Returns:
        a reference to this builder.

    - #### setAuthoritativeAnswer

          public DnsMessage.Builder setAuthoritativeAnswer(boolean authoritativeAnswer)

      Set the authoritative answer flag.
      Parameters:
        `authoritativeAnswer` - Tge new authoritative answer value.
      Returns:
        a reference to this builder.

    - #### setCheckDisabled

          @Deprecated
          public DnsMessage.Builder setCheckDisabled(boolean checkingDisabled)

      Deprecated.
      Change the check status of this packet.
      Parameters:
        `checkingDisabled` - The new check disabled value.
      Returns:
        a reference to this builder.

    - #### setCheckingDisabled

          public DnsMessage.Builder setCheckingDisabled(boolean checkingDisabled)

      Change the check status of this packet.
      Parameters:
        `checkingDisabled` - The new check disabled value.
      Returns:
        a reference to this builder.

    - #### setId

          public DnsMessage.Builder setId(int id)

      Set the current DNS message id.
      Parameters:
        `id` - The new DNS message id.
      Returns:
        a reference to this builder.

    - #### setNameserverRecords

          public DnsMessage.Builder setNameserverRecords(Collection<Record<? extends Data>> records)

    - #### setOpcode

          public DnsMessage.Builder setOpcode(DnsMessage.OPCODE opcode)

    - #### setQrFlag

          public DnsMessage.Builder setQrFlag(boolean query)

      Set the QR flag. Note that this will be `true` if the message is a response and `false` if it is a query.
      Parameters:
        `query` - The new QR flag status.
      Returns:
        a reference to this builder.

    - #### setQuestion

          public DnsMessage.Builder setQuestion(Question question)

      Set the question part of this message.
      Parameters:
        `question` - The question.
      Returns:
        a reference to this builder.

    - #### setQuestions

          public DnsMessage.Builder setQuestions(List<Question> questions)

      Set the question part of this message.
      Parameters:
        `questions` - The questions.
      Returns:
        a reference to this builder.

    - #### setReceiveTimestamp

          public DnsMessage.Builder setReceiveTimestamp(long receiveTimestamp)

    - #### setRecursionAvailable

          public DnsMessage.Builder setRecursionAvailable(boolean recursionAvailable)

      Set the recursion available flog from this DNS message.
      Parameters:
        `recursionAvailable` - The new recursion available status.
      Returns:
        a reference to this builder.

    - #### setRecursionDesired

          public DnsMessage.Builder setRecursionDesired(boolean recursionDesired)

      Set the recursion desired flag on this message.
      Parameters:
        `recursionDesired` - The new recusrion setting.
      Returns:
        a reference to this builder.

    - #### setResponseCode

          public DnsMessage.Builder setResponseCode(DnsMessage.RESPONSE_CODE responseCode)

    - #### setTruncated

          public DnsMessage.Builder setTruncated(boolean truncated)

      Set the truncation bit on this DNS message.
      Parameters:
        `truncated` - The new truncated bit status.
      Returns:
        a reference to this builder.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`