org.xbill.DNS.utils
Class DataByteInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.ByteArrayInputStream
          extended byorg.xbill.DNS.utils.DataByteInputStream

public class DataByteInputStream
extends ByteArrayInputStream

An extension of ByteArrayInputStream to support directly reading types used by DNS routines.

Author:
Brian Wellington
See Also:
DataByteOutputStream

Field Summary
 
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
 
Constructor Summary
DataByteInputStream(byte[] b)
          Creates a new DataByteInputStream
 
Method Summary
 int getPos()
          Get the current position in the stream
 int read(byte[] b)
          Read data from the stream.
 int readArray(byte[] b, int pos, int len)
          Read data from the stream.
 BigInteger readBigInteger(int len)
          Read a BigInteger from the stream, encoded as binary data.
 byte readByte()
          Read a byte from the stream
 int readInt()
          Read an int from the stream
 long readLong()
          Read a long from the stream
 short readShort()
          Read a short from the stream
 String readString()
          Read a String from the stream, represented as a length byte followed by data
 byte[] readStringIntoArray()
          Read a String from the stream, represented as a length byte followed by data, and encode it in a byte array.
 int readUnsignedByte()
          Read an unsigned byte from the stream
 int readUnsignedShort()
          Read an unsigned short from the stream
 void setPos(int pos)
          Sets the current position in the stream
 void skipBytes(int n)
          Read and ignore bytes from the stream
 
Methods inherited from class java.io.ByteArrayInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataByteInputStream

public DataByteInputStream(byte[] b)
Creates a new DataByteInputStream

Parameters:
b - The byte array to read from
Method Detail

read

public int read(byte[] b)
         throws IOException
Read data from the stream.

Parameters:
b - The array to read into
Returns:
The number of bytes read
Throws:
IOException

readArray

public int readArray(byte[] b,
                     int pos,
                     int len)
              throws IOException
Read data from the stream.

Parameters:
b - The array to read into
pos - The starting position
len - The number of bytes to read
Returns:
The number of bytes read
Throws:
IOException

readByte

public byte readByte()
              throws IOException
Read a byte from the stream

Returns:
The byte
Throws:
IOException

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Read an unsigned byte from the stream

Returns:
The unsigned byte as an int
Throws:
IOException

readShort

public short readShort()
                throws IOException
Read a short from the stream

Returns:
The short
Throws:
IOException

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Read an unsigned short from the stream

Returns:
The unsigned short as an int
Throws:
IOException

readInt

public int readInt()
            throws IOException
Read an int from the stream

Returns:
The int
Throws:
IOException

readLong

public long readLong()
              throws IOException
Read a long from the stream

Returns:
The long
Throws:
IOException

readStringIntoArray

public byte[] readStringIntoArray()
                           throws IOException
Read a String from the stream, represented as a length byte followed by data, and encode it in a byte array.

Returns:
The array
Throws:
IOException

readString

public String readString()
                  throws IOException
Read a String from the stream, represented as a length byte followed by data

Returns:
The String
Throws:
IOException

readBigInteger

public BigInteger readBigInteger(int len)
                          throws IOException
Read a BigInteger from the stream, encoded as binary data. A 0 byte is prepended so that the value is always positive.

Parameters:
len - The number of bytes to read
Returns:
The BigInteger
Throws:
IOException

skipBytes

public void skipBytes(int n)
               throws IOException
Read and ignore bytes from the stream

Parameters:
n - The number of bytes to skip
Throws:
IOException

getPos

public int getPos()
Get the current position in the stream

Returns:
The current position

setPos

public void setPos(int pos)
Sets the current position in the stream