Interface ZigBeeDataOutput


public interface ZigBeeDataOutput
The ZigBeeDataOutput interface is designed for converting Java data types into a series of bytes. The purpose of this interface is the same as the DataOutput interface provided by Java, with the difference that in this interface, the generated bytes ordering is little endian, whereas in the DataOutput is big endian.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    writeByte(byte value)
    Appends a byte to the data output.
    void
    writeBytes(byte[] bytes, int length)
    Appends on the Data Output Stream a byte array.
    void
    writeDouble(double value)
    Appends on the Data Output Stream a double value.
    void
    writeFloat(float value, int size)
    Appends on the Data Output Stream a float value.
    void
    writeInt(int value, int size)
    Appends an int value to the data output.
    void
    writeLong(long value, int size)
    Appends a long to the data output.
  • Method Details

    • writeByte

      void writeByte(byte value)
      Appends a byte to the data output.

      To avoid losing information, the passed value must be in the range [-128, 127] for signed numbers and [0, 255] for unsigned numbers.

      Parameters:
      value - The value to append.
    • writeInt

      void writeInt(int value, int size) throws IOException
      Appends an int value to the data output.

      To avoid losing information, according to the size argument, the passed long value if it represents a signed number must fit in the range [ -2^(size * 8 - 1), -2^(size * 8 - 1) - 1].

      For unsigned numbers it should fit in the range [ 0, -2^(size * 8) - 1].

      For instance if size is 2 the correct range for signed numbers is [0xffff8000, 0x7fff] (that is, [-32768, +32767]), whereas for unsigned numbers is [0L, 0xffff].

      Although this method allows write even 1 byte of the passed int value, it is suggested to use the writeByte(byte) because this latter could be implemented in a more efficient way.

      Parameters:
      value - The integer value to append
      size - The size in bytes that have to be actually appended. The size must be in the range [1,4].
      Throws:
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed size is not within the allowed range.
    • writeLong

      void writeLong(long value, int size) throws IOException
      Appends a long to the data output.

      To avoid losing information, according to the size argument, the passed long value if it represents a signed number must fit in the range [ -2^(size * 8 - 1), -2^(size * 8 - 1) - 1].

      For unsigned numbers it should fit in the range [ 0, -2^(size * 8) - 1].

      For instance if size is 3 the correct range for signed numbers is [0xffffffffff800000L, 0x7fffffL] (that is, [-21474836448, +2147483647]), whereas for unsigned numbers is [0L, 0xffffffL].

      Although this method allows write even 1 byte of the passed long value, it is suggested to use the writeByte(byte) because this latter could be implemented in a more efficient way.

      Parameters:
      value - The long value to append
      size - The size in bytes that have to be actually appended. The size must be in the range [1,8].
      Throws:
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed size is not within the allowed range.
    • writeFloat

      void writeFloat(float value, int size) throws IOException
      Appends on the Data Output Stream a float value.
      Parameters:
      value - The float value to append.
      size - The size in bytes that have to be actually appended. The size must be 2 for semi precision floats or 4 for standard precision floats (see the ZigBee Cluster Library specifications).
      Throws:
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed size is not within the allowed range.
    • writeDouble

      void writeDouble(double value) throws IOException
      Appends on the Data Output Stream a double value.
      Parameters:
      value - The double value to append.
      Throws:
      IOException - If an I/O error occurs.
    • writeBytes

      void writeBytes(byte[] bytes, int length) throws IOException
      Appends on the Data Output Stream a byte array. The byte array is written on the data output starting from the byte at index 0.
      Parameters:
      bytes - A buffer containing the bytes to append to the data output stream.
      length - The length in bytes that have to be actually appended.
      Throws:
      IOException - If an I/O error occurs.
      IllegalArgumentException - If the passed buffer is null or shorter than length bytes.