- java.lang.Object
-
- com.ibm.dataaccess.ByteArrayUnmarshaller
-
public final class ByteArrayUnmarshaller extends Object
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,
-1as one signed byte is0xFF. UsingreadShortwithsignExtendtrue, the resultant short will contain0xFFFF, which is-1in Java's signed format. WithsignExtendfalse, the resultant short will contain0x00FF, which is255.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doublereadDouble(byte[] byteArray, int offset, boolean bigEndian)Returns a double value copied from eight consecutive bytes of the byte array starting at the offset.static floatreadFloat(byte[] byteArray, int offset, boolean bigEndian)Returns a float value copied from four consecutive bytes of the byte array starting at the offset.static intreadInt(byte[] byteArray, int offset, boolean bigEndian)Returns an int value copied from four consecutive bytes starting at the offset.static intreadInt(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 longreadLong(byte[] byteArray, int offset, boolean bigEndian)Returns a long value copied from eight consecutive bytes of the byte array starting at the offset.static longreadLong(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 shortreadShort(byte[] byteArray, int offset, boolean bigEndian)Returns a short value copied from two consecutive bytes of the byte array starting at the offset.static shortreadShort(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 Detail
-
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- ifbyteArrayis 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 < 2then the topmost bytes of the returned short will be sign extended- Returns:
- long
- Throws:
NullPointerException- ifbyteArrayis nullIllegalArgumentException- ifnumBytes < 0ornumBytes > 2ArrayIndexOutOfBoundsException- 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 < 4then the topmost bytes of the returned int will be sign extended- Returns:
- int
- Throws:
NullPointerException- ifbyteArrayis nullIllegalArgumentException- ifnumBytes < 0ornumBytes > 4ArrayIndexOutOfBoundsException- 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- ifbyteArrayis 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 < 8then the topmost bytes of the returned long will be sign extended- Returns:
- long
- Throws:
NullPointerException- ifbyteArrayis nullIllegalArgumentException- ifnumBytes < 0ornumBytes > 8ArrayIndexOutOfBoundsException- 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- ifbyteArrayis 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- ifbyteArrayis nullArrayIndexOutOfBoundsException- if an invalid array access occurs
-
-