java.lang.Object
com.ibm.dataaccess.ByteArrayUnmarshaller
Conversion routines to unmarshall Java binary types (short, int, long, float,
double) from byte arrays.
With sign extensions enabled, the marshalled data is interpreted as signed
and the data will be appropriately converted into the return type container.
With sign extensions disabled, unfilled bits in the container will be set to
zero. For example, -1
as one signed byte is 0xFF
.
Using readShort
with signExtend
true, the resultant
short will contain 0xFFFF
, which is -1
in Java's
signed format. With signExtend
false, the resultant short will
contain 0x00FF
, which is 255
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
readDouble
(byte[] byteArray, int offset, boolean bigEndian) Returns a double value copied from eight consecutive bytes of the byte array starting at the offset.static float
readFloat
(byte[] byteArray, int offset, boolean bigEndian) Returns a float value copied from four consecutive bytes of the byte array starting at the offset.static int
readInt
(byte[] byteArray, int offset, boolean bigEndian) Returns an int value copied from four consecutive bytes starting at the offset.static int
readInt
(byte[] byteArray, int offset, boolean bigEndian, int numBytes, boolean signExtend) Returns an int value copied from zero to four consecutive bytes of the byte array starting at the offset.static long
readLong
(byte[] byteArray, int offset, boolean bigEndian) Returns a long value copied from eight consecutive bytes of the byte array starting at the offset.static long
readLong
(byte[] byteArray, int offset, boolean bigEndian, int numBytes, boolean signExtend) Returns a long value copied from zero to eight consecutive bytes of the byte array starting at the offset.static short
readShort
(byte[] byteArray, int offset, boolean bigEndian) Returns a short value copied from two consecutive bytes of the byte array starting at the offset.static short
readShort
(byte[] byteArray, int offset, boolean bigEndian, int numBytes, boolean signExtend) Returns a short value copied from zero to two consecutive bytes of the byte array starting at the offset.
-
Method Details
-
readShort
public static short readShort(byte[] byteArray, int offset, boolean bigEndian) Returns a short value copied from two consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) order- Returns:
- short
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readShort
public static short readShort(byte[] byteArray, int offset, boolean bigEndian, int numBytes, boolean signExtend) Returns a short value copied from zero to two consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) ordernumBytes
- the number of bytes to unmarshall, must be 0-2 inclusivesignExtend
- if true andnumBytes < 2
then the topmost bytes of the returned short will be sign extended- Returns:
- long
- Throws:
NullPointerException
- ifbyteArray
is nullIllegalArgumentException
- ifnumBytes < 0
ornumBytes > 2
ArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readInt
public static int readInt(byte[] byteArray, int offset, boolean bigEndian) Returns an int value copied from four consecutive bytes starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) order- Returns:
- int
- Throws:
NullPointerException
- if byteArray is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readInt
public static int readInt(byte[] byteArray, int offset, boolean bigEndian, int numBytes, boolean signExtend) Returns an int value copied from zero to four consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) ordernumBytes
- the number of bytes to unmarshall, must be 0-4 inclusivesignExtend
- if true andnumBytes < 4
then the topmost bytes of the returned int will be sign extended- Returns:
- int
- Throws:
NullPointerException
- ifbyteArray
is nullIllegalArgumentException
- ifnumBytes < 0
ornumBytes > 4
ArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readLong
public static long readLong(byte[] byteArray, int offset, boolean bigEndian) Returns a long value copied from eight consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) order- Returns:
- long
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readLong
public static long readLong(byte[] byteArray, int offset, boolean bigEndian, int numBytes, boolean signExtend) Returns a long value copied from zero to eight consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) ordernumBytes
- the number of bytes to unmarshall, must be 0-8 inclusivesignExtend
- if true andnumBytes < 8
then the topmost bytes of the returned long will be sign extended- Returns:
- long
- Throws:
NullPointerException
- ifbyteArray
is nullIllegalArgumentException
- ifnumBytes < 0
ornumBytes > 8
ArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readFloat
public static float readFloat(byte[] byteArray, int offset, boolean bigEndian) Returns a float value copied from four consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) order- Returns:
- float
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-
readDouble
public static double readDouble(byte[] byteArray, int offset, boolean bigEndian) Returns a double value copied from eight consecutive bytes of the byte array starting at the offset.- Parameters:
byteArray
- sourceoffset
- offset in the byte arraybigEndian
- if false the bytes will be copied in reverse (little endian) order- Returns:
- double
- Throws:
NullPointerException
- ifbyteArray
is nullArrayIndexOutOfBoundsException
- if an invalid array access occurs
-