Package org.xbill.DNS
Class DNSInput
java.lang.Object
org.xbill.DNS.DNSInput
A class for parsing DNS messages.
- Author:
- Brian Wellington
-
Constructor Summary
ConstructorsConstructorDescriptionDNSInput(byte[] input) Creates a new DNSInputDNSInput(ByteBuffer byteBuffer) Creates a new DNSInput from the givenByteBuffer -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the active region of the string.intcurrent()Returns the current position.voidjump(int index) Resets the current position of the input stream to the specified index, and clears the active region.byte[]Reads a byte array consisting of the remainder of the stream (or the active region, if one is set.voidreadByteArray(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[]Reads a counted string from the stream.intreadU16()Reads an unsigned 16 bit value from the stream, as an int.longreadU32()Reads an unsigned 32 bit value from the stream, as a long.intreadU8()Reads an unsigned 8 bit value from the stream, as an int.intReturns the number of bytes that can be read from this stream before reaching the end.voidrestore()Restores the input stream to its state before the call tosave().voidrestoreActive(int pos) Restores the previously set active region.voidsave()Saves the current state of the input stream.intReturns the position of the end of the current active region.voidsetActive(int len) Marks the following bytes in the stream as active.
-
Constructor Details
-
DNSInput
public DNSInput(byte[] input) Creates a new DNSInput- Parameters:
input- The byte array to read from
-
DNSInput
Creates a new DNSInput from the givenByteBuffer- Parameters:
byteBuffer- The ByteBuffer
-
-
Method Details
-
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 tosave(). -
readU8
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
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
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
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
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
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.
-