Package org.osgi.service.zigbee
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 TypeMethodDescriptionbyte
readByte()
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 specifiedsize
.long
readLong
(int size) Reads a certain amount of bytes and returns a long.
-
Method Details
-
readByte
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
Reads an integer of the specifiedsize
. The sign bit of thesize
-bytes integer is left-extended. In other words if areadInt(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 passedsize
is not in the allowed range.
-
readLong
Reads a certain amount of bytes and returns a long. The sign bit of the readsize
-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 leastsize
bytes left on the data input.IOException
- If an I/O error occurs.IllegalArgumentException
- If the passedsize
is not in the allowed range.
-
readFloat
Reads a number of type Float.- Parameters:
size
- expected value for this parameter are 2 or 4 depending if readingZigBeeDataTypes.FLOATING_SEMI
orZigBeeDataTypes.FLOATING_SINGLE
.- Returns:
- The
float
number read from the data input. - Throws:
EOFException
- if there are not at leastsize
bytes left on the data input.IOException
- If an I/O error occurs.IllegalArgumentException
- If the passedsize
is not in the allowed range.
-
readDouble
Reads a number of type Double.- Returns:
- a decoded double.
- Throws:
EOFException
- if there are not at leastsize
8 bytes left on the data input.IOException
- If an I/O error occurs.
-
readBytes
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 leastlen
bytes left on the data input.IOException
- If an I/O error occurs.
-