Package org.osgi.service.zigbee
Interface ZigBeeDataInput
-
public interface ZigBeeDataInputTheZigBeeDataInputinterface is designed for converting a series of bytes in Java data types. The purpose of this interface is the same as theDataInputinterface 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.- Author:
- $Id: bec827b3b3c1dc2b4a4ca973636585f44f8d01ad $
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description bytereadByte()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.doublereadDouble()Reads a number of type Double.floatreadFloat(int size)Reads a number of type Float.intreadInt(int size)Reads an integer of the specifiedsize.longreadLong(int size)Reads a certain amount of bytes and returns a long.
-
-
-
Method Detail
-
readByte
byte readByte() throws java.io.IOExceptionReads a byte from the DataInput Stream.- Returns:
- the byte read from the data input.
- Throws:
java.io.EOFException- When the end of the input has been reached and there are no more data to read.java.io.IOException- If an I/O error occurs.
-
readInt
int readInt(int size) throws java.io.IOExceptionReads 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:
java.io.EOFException- When the end of the input has been reached and there are no more data to read.java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passedsizeis not in the allowed range.
-
readLong
long readLong(int size) throws java.io.IOExceptionReads 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
longvalue read from the data input. - Throws:
java.io.EOFException- if there are not at leastsizebytes left on the data input.java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passedsizeis not in the allowed range.
-
readFloat
float readFloat(int size) throws java.io.IOExceptionReads a number of type Float.- Parameters:
size- expected value for this parameter are 2 or 4 depending if readingZigBeeDataTypes.FLOATING_SEMIorZigBeeDataTypes.FLOATING_SINGLE.- Returns:
- The
floatnumber read from the data input. - Throws:
java.io.EOFException- if there are not at leastsizebytes left on the data input.java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If the passedsizeis not in the allowed range.
-
readDouble
double readDouble() throws java.io.IOExceptionReads a number of type Double.- Returns:
- a decoded double.
- Throws:
java.io.EOFException- if there are not at leastsize8 bytes left on the data input.java.io.IOException- If an I/O error occurs.
-
readBytes
byte[] readBytes(int len) throws java.io.IOExceptionReads 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:
java.io.EOFException- if there are not at leastlenbytes left on the data input.java.io.IOException- If an I/O error occurs.
-
-