public interface ZigBeeDataOutput
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.Modifier and Type | Method and 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.
|
void writeByte(byte value)
To avoid losing information, the passed value must be in the range [-128, 127] for signed numbers and [0, 255] for unsigned numbers.
value
- The value to append.void writeInt(int value, int size) throws IOException
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.
value
- The integer value to appendsize
- The size in bytes that have to be actually appended. The size
must be in the range [1,4].IOException
- If an I/O error occurs.IllegalArgumentException
- If the passed size
is not within
the allowed range.void writeLong(long value, int size) throws IOException
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.
value
- The long
value to appendsize
- The size in bytes that have to be actually appended. The size
must be in the range [1,8].IOException
- If an I/O error occurs.IllegalArgumentException
- If the passed size
is not within
the allowed range.void writeFloat(float value, int size) throws IOException
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).IOException
- If an I/O error occurs.IllegalArgumentException
- If the passed size
is not within
the allowed range.void writeDouble(double value) throws IOException
double
value.value
- The double
value to append.IOException
- If an I/O error occurs.void writeBytes(byte[] bytes, int length) throws IOException
bytes
- A buffer containing the bytes to append to the data output
stream.length
- The length in bytes that have to be actually appended.IOException
- If an I/O error occurs.IllegalArgumentException
- If the passed buffer is null or shorter
than length
bytes.Copyright © Contributors to the Eclipse Foundation Licensed under the Eclipse Foundation Specification License – v1.0