Interface ZigBeeDataInput


public interface ZigBeeDataInput
The ZigBeeDataInput interface is designed for converting a series of bytes in Java data types. The purpose of this interface is the same as the DataInput interface available in the standard Java library, with the difference that in this interface, byte ordering is little endian, whereas in the DataInput interface is big endian.

Each method provided by this interface read one or more bytes from the underlying stream, combine them, and return a Java data type. The pointer to the stream is then moved immediately after the last byte read. If this pointer past the available buffer bounds, a subsequent call to one of these methods will throw a EOFException.

  • Method Summary

    Modifier and Type
    Method
    Description
    byte
    Reads a byte from the DataInput Stream.
    byte[]
    readBytes(int len)
    Reads the specified amount of bytes from the underlying stream and return a copy of them.
    double
    Reads a number of type Double.
    float
    readFloat(int size)
    Reads a number of type Float.
    int
    readInt(int size)
    Reads an integer of the specified size.
    long
    readLong(int size)
    Reads a certain amount of bytes and returns a long.
  • Method Details

    • readByte

      byte readByte() throws IOException
      Reads a byte from the DataInput Stream.
      Returns:
      the byte read from the data input.
      Throws:
      EOFException - When the end of the input has been reached and there are no more data to read.
      IOException - If an I/O error occurs.
    • readInt

      int readInt(int size) throws IOException
      Reads an integer of the specified size. The sign bit of the size-bytes integer is left-extended. In other words if a readInt(2) is issued and the byte read are 0x01, 0x02 and 0xf0, the method returns 0xfff00201. For this reason if the 4 bytes read from the stream represent an unsigned value, to get the expected value the and bitwise operator must be used:

      int u = readInt(3) & 0xffffff;

      Parameters:
      size - the number of bytes that have to be read. Allowed values for this parameter are in the range [1, 4].
      Returns:
      the integer read from the data input.
      Throws:
      EOFException - When the end of the input has been reached and there are no more data to read.
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed size is not in the allowed range.
    • readLong

      long readLong(int size) throws IOException
      Reads a certain amount of bytes and returns a long. The sign bit of the read size-bytes long is left-extended. In other words if a readLong(2) is issued and the byte read are 0x01 and 0xf0, the method returns 0xfffffffffffff001L. For this reason if the 2 bytes read from the stream represent an unsigned value, to get the expected value the and bitwise operator must be used:

      long u = readLong(2) & 0xffff;

      Parameters:
      size - the number of bytes that have to be read. Allowed values for this parameter are in the range [1, 8].
      Returns:
      The long value read from the data input.
      Throws:
      EOFException - if there are not at least size bytes left on the data input.
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed size is not in the allowed range.
    • readFloat

      float readFloat(int size) throws IOException
      Reads a number of type Float.
      Parameters:
      size - expected value for this parameter are 2 or 4 depending if reading ZigBeeDataTypes.FLOATING_SEMI or ZigBeeDataTypes.FLOATING_SINGLE.
      Returns:
      The float number read from the data input.
      Throws:
      EOFException - if there are not at least size bytes left on the data input.
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed size is not in the allowed range.
    • readDouble

      double readDouble() throws IOException
      Reads a number of type Double.
      Returns:
      a decoded double.
      Throws:
      EOFException - if there are not at least size 8 bytes left on the data input.
      IOException - If an I/O error occurs.
    • readBytes

      byte[] readBytes(int len) throws IOException
      Reads the specified amount of bytes from the underlying stream and return a copy of them. If the number of available bytes is less than the requested len, it throws an EOFException.
      Parameters:
      len - the number of bytes to read.
      Returns:
      return a copy of the bytes contained in the stream.
      Throws:
      EOFException - if there are not at least len bytes left on the data input.
      IOException - If an I/O error occurs.