DNSInput (dnsjava documentation)
Date: 2013-04-10

org.xbill.DNS

## Class DNSInput

- java.lang.Object
- - org.xbill.DNS.DNSInput

-     public class DNSInput
      extends Object

  An class for parsing DNS messages.
  Author:
    Brian Wellington

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DNSInput(byte[] input)` Creates a new DNSInput

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clearActive()` Clears the active region of the string.
    `int` | `current()` Returns the current position.
    `void` | `jump(int index)` Resets the current position of the input stream to the specified index, and clears the active region.
    `byte[]` | `readByteArray()` Reads a byte array consisting of the remainder of the stream (or the active region, if one is set.
    `void` | `readByteArray(byte[] b, int off, int len)` Reads a byte array of a specified length from the stream into an existing array.
    `byte[]` | `readByteArray(int len)` Reads a byte array of a specified length from the stream.
    `byte[]` | `readCountedString()` Reads a counted string from the stream.
    `int` | `readU16()` Reads an unsigned 16 bit value from the stream, as an int.
    `long` | `readU32()` Reads an unsigned 32 bit value from the stream, as a long.
    `int` | `readU8()` Reads an unsigned 8 bit value from the stream, as an int.
    `int` | `remaining()` Returns the number of bytes that can be read from this stream before reaching the end.
    `void` | `restore()` Restores the input stream to its state before the call to `save()`.
    `void` | `restoreActive(int pos)` Restores the previously set active region.
    `void` | `save()` Saves the current state of the input stream.
    `int` | `saveActive()` Returns the position of the end of the current active region.
    `void` | `setActive(int len)` Marks the following bytes in the stream as active.

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

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

- - ### Constructor Detail

    - #### DNSInput

          public DNSInput(byte[] input)

      Creates a new DNSInput
      Parameters:
        `input` - The byte array to read from

  - ### Method Detail

    - #### current

          public int current()

      Returns the current position.

    - #### remaining

          public int remaining()

      Returns the number of bytes that can be read from this stream before reaching the end.

    - #### setActive

          public void setActive(int len)

      Marks the following bytes in the stream as active.
      Parameters:
        `len` - The number of bytes in the active region.
      Throws:
        `IllegalArgumentException` - The number of bytes in the active region is longer than the remainder of the input.

    - #### clearActive

          public void clearActive()

      Clears the active region of the string. Further operations are not restricted to part of the input.

    - #### saveActive

          public int saveActive()

      Returns the position of the end of the current active region.

    - #### restoreActive

          public void restoreActive(int pos)

      Restores the previously set active region. This differs from setActive() in that restoreActive() takes an absolute position, and setActive takes an offset from the current location.
      Parameters:
        `pos` - The end of the active region.

    - #### jump

          public void jump(int index)

      Resets the current position of the input stream to the specified index, and clears the active region.
      Parameters:
        `index` - The position to continue parsing at.
      Throws:
        `IllegalArgumentException` - The index is not within the input.

    - #### save

          public void save()

      Saves the current state of the input stream. Both the current position and the end of the active region are saved.
      Throws:
        `IllegalArgumentException` - The index is not within the input.

    - #### restore

          public void restore()

      Restores the input stream to its state before the call to `save()`.

    - #### readU8

          public int readU8()
                     throws WireParseException

      Reads an unsigned 8 bit value from the stream, as an int.
      Returns:
        An unsigned 8 bit value.
      Throws:
        `WireParseException` - The end of the stream was reached.

    - #### readU16

          public int readU16()
                      throws WireParseException

      Reads an unsigned 16 bit value from the stream, as an int.
      Returns:
        An unsigned 16 bit value.
      Throws:
        `WireParseException` - The end of the stream was reached.

    - #### readU32

          public long readU32()
                       throws WireParseException

      Reads an unsigned 32 bit value from the stream, as a long.
      Returns:
        An unsigned 32 bit value.
      Throws:
        `WireParseException` - The end of the stream was reached.

    - #### readByteArray

          public void readByteArray(byte[] b,
                           int off,
                           int len)
                             throws WireParseException

      Reads a byte array of a specified length from the stream into an existing array.
      Parameters:
        `b` - The array to read into.
        `off` - The offset of the array to start copying data into.
        `len` - The number of bytes to copy.
      Throws:
        `WireParseException` - The end of the stream was reached.

    - #### readByteArray

          public byte[] readByteArray(int len)
                               throws WireParseException

      Reads a byte array of a specified length from the stream.
      Returns:
        The byte array.
      Throws:
        `WireParseException` - The end of the stream was reached.

    - #### readByteArray

          public byte[] readByteArray()

      Reads a byte array consisting of the remainder of the stream (or the active region, if one is set.
      Returns:
        The byte array.

    - #### readCountedString

          public byte[] readCountedString()
                                   throws WireParseException

      Reads a counted string from the stream. A counted string is a one byte value indicating string length, followed by bytes of data.
      Returns:
        A byte array containing the string.
      Throws:
        `WireParseException` - The end of the stream was reached.