com.ibm.as400.access
Class BinaryConverter

java.lang.Object
  extended by com.ibm.as400.access.BinaryConverter

public class BinaryConverter
extends Object

A binary types converter between Java byte arrays and Java simple types.


Method Summary
Modifier and Type Method and Description
static double byteArrayToDouble(byte[] serverValue, int offset)
          Convert the specified IBM i data type to a double.
static float byteArrayToFloat(byte[] serverValue, int offset)
          Convert the specified IBM i data type to a float.
static int byteArrayToInt(byte[] serverValue, int offset)
          Convert the specified IBM i data type to an int.
static long byteArrayToLong(byte[] serverValue, int offset)
          Convert the specified IBM i data type to a long.
static short byteArrayToShort(byte[] serverValue, int offset)
          Convert the specified IBM i data type to a short.
static long byteArrayToUnsignedInt(byte[] serverValue, int offset)
          Convert the specified IBM i data type to a long.
static int byteArrayToUnsignedShort(byte[] serverValue, int offset)
          Convert the specified IBM i data type to an int.
static String bytesToString(byte[] b)
          Convert the specified byte array to its hexadecimal String representation.
static String bytesToString(byte[] b, int offset, int length)
          Convert the specified byte array to its hexadecimal String representation.
static byte[] doubleToByteArray(double doubleValue)
          Convert the specified double into IBM i format in a byte array.
static void doubleToByteArray(double doubleValue, byte[] serverValue, int offset)
          Convert the specified double into IBM i format in the specified byte array.
static byte[] floatToByteArray(float floatValue)
          Convert the specified float into IBM i format in a byte array.
static void floatToByteArray(float floatValue, byte[] serverValue, int offset)
          Convert the specified float into IBM i format in the specified byte array.
static byte[] floatToByteArray(int floatValue)
          Deprecated. Use floatToByteArray(float) instead.
static byte[] intToByteArray(int intValue)
          Convert the specified int into IBM i format in a byte array.
static void intToByteArray(int intValue, byte[] serverValue, int offset)
          Convert the specified int into IBM i format in the specified byte array.
static byte[] longToByteArray(long longValue)
          Convert the specified long into IBM i format in a byte array.
static void longToByteArray(long longValue, byte[] serverValue, int offset)
          Convert the specified long into IBM i format in the specified byte array.
static byte[] shortToByteArray(short shortValue)
          Convert the specified short into IBM i format in a byte array.
static void shortToByteArray(short shortValue, byte[] serverValue, int offset)
          Convert the specified short into IBM i format in the specified byte array.
static byte[] stringToBytes(String s)
          Convert the specified hexadecimal String into a byte array containing the byte values for the hexadecimal characters in the String.
static byte[] unsignedIntToByteArray(long longValue)
          Convert the specified long into IBM i format in a byte array.
static void unsignedIntToByteArray(long longValue, byte[] serverValue, int offset)
          Convert the specified long into IBM i format in the specified byte array.
static byte[] unsignedShortToByteArray(int intValue)
          Convert the specified int into IBM i format in a byte array.
static void unsignedShortToByteArray(int intValue, byte[] serverValue, int offset)
          Convert the specified int into IBM i format in the specified byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

shortToByteArray

public static void shortToByteArray(short shortValue,
                                    byte[] serverValue,
                                    int offset)
Convert the specified short into IBM i format in the specified byte array. The converted value will occupy 2 bytes.

Parameters:
shortValue - The value to be converted to IBM i format.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

shortToByteArray

public static byte[] shortToByteArray(short shortValue)
Convert the specified short into IBM i format in a byte array.

Parameters:
shortValue - The value to be converted to IBM i format.
Returns:
An array (of length 2) with the data type in IBM i format.

byteArrayToShort

public static short byteArrayToShort(byte[] serverValue,
                                     int offset)
Convert the specified IBM i data type to a short.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
a short corresponding to the data type.

intToByteArray

public static void intToByteArray(int intValue,
                                  byte[] serverValue,
                                  int offset)
Convert the specified int into IBM i format in the specified byte array. The converted value will occupy 4 bytes.

Parameters:
intValue - The value to be converted to IBM i format.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

intToByteArray

public static byte[] intToByteArray(int intValue)
Convert the specified int into IBM i format in a byte array.

Parameters:
intValue - The value to be converted to IBM i format.
Returns:
An array (of length 4) with the data type in IBM i format.

byteArrayToInt

public static int byteArrayToInt(byte[] serverValue,
                                 int offset)
Convert the specified IBM i data type to an int.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
an int corresponding to the data type.

floatToByteArray

public static void floatToByteArray(float floatValue,
                                    byte[] serverValue,
                                    int offset)
Convert the specified float into IBM i format in the specified byte array. The converted value will occupy 4 bytes.

Parameters:
floatValue - The value to be converted to IBM i format.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

floatToByteArray

public static byte[] floatToByteArray(int floatValue)
Deprecated. Use floatToByteArray(float) instead.

Convert the specified float into IBM i format in a byte array.

Parameters:
floatValue - The value to be converted to IBM i format.
Returns:
An array (of length 4) with the data type in IBM i format.

floatToByteArray

public static byte[] floatToByteArray(float floatValue)
Convert the specified float into IBM i format in a byte array.

Parameters:
floatValue - The value to be converted to IBM i format.
Returns:
An array (of length 4) with the data type in IBM i format.

byteArrayToFloat

public static float byteArrayToFloat(byte[] serverValue,
                                     int offset)
Convert the specified IBM i data type to a float.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
a float corresponding to the data type.

doubleToByteArray

public static void doubleToByteArray(double doubleValue,
                                     byte[] serverValue,
                                     int offset)
Convert the specified double into IBM i format in the specified byte array. The converted value will occupy 8 bytes.

Parameters:
doubleValue - The value to be converted to IBM i format.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

doubleToByteArray

public static byte[] doubleToByteArray(double doubleValue)
Convert the specified double into IBM i format in a byte array.

Parameters:
doubleValue - The value to be converted to IBM i format.
Returns:
An array (of length 8) with the data type in IBM i format.

byteArrayToDouble

public static double byteArrayToDouble(byte[] serverValue,
                                       int offset)
Convert the specified IBM i data type to a double.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
a double corresponding to the data type.

unsignedShortToByteArray

public static void unsignedShortToByteArray(int intValue,
                                            byte[] serverValue,
                                            int offset)
Convert the specified int into IBM i format in the specified byte array. The converted value will occupy 2 bytes.

Parameters:
intValue - The value to be converted to IBM i format. The integer should be greater than or equal to zero and representable in two bytes.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

unsignedShortToByteArray

public static byte[] unsignedShortToByteArray(int intValue)
Convert the specified int into IBM i format in a byte array.

Parameters:
intValue - The value to be converted to IBM i format. The integer should be greater than or equal to zero and representable in two bytes.
Returns:
An array (of length 2) with the data type in IBM i format.

byteArrayToUnsignedShort

public static int byteArrayToUnsignedShort(byte[] serverValue,
                                           int offset)
Convert the specified IBM i data type to an int.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
an int corresponding to the data type, derived from the 2 bytes of data starting at the specified offset.

unsignedIntToByteArray

public static void unsignedIntToByteArray(long longValue,
                                          byte[] serverValue,
                                          int offset)
Convert the specified long into IBM i format in the specified byte array. The converted value will occupy 4 bytes.

Parameters:
longValue - The value to be converted to IBM i format. The long should be greater than or equal to zero and representable in four bytes.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

unsignedIntToByteArray

public static byte[] unsignedIntToByteArray(long longValue)
Convert the specified long into IBM i format in a byte array.

Parameters:
longValue - The value to be converted to IBM i format. The long should be greater than or equal to zero and representable in four bytes.
Returns:
An array (of length 4) with the data type in IBM i format.

byteArrayToUnsignedInt

public static long byteArrayToUnsignedInt(byte[] serverValue,
                                          int offset)
Convert the specified IBM i data type to a long.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
a long corresponding to the data type.

longToByteArray

public static void longToByteArray(long longValue,
                                   byte[] serverValue,
                                   int offset)
Convert the specified long into IBM i format in the specified byte array. The converted value will occupy 8 bytes.

Parameters:
longValue - The value to be converted to IBM i format.
serverValue - The array to receive the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.

longToByteArray

public static byte[] longToByteArray(long longValue)
Convert the specified long into IBM i format in a byte array.

Parameters:
longValue - The value to be converted to IBM i format.
Returns:
An array (of length 8) with the data type in IBM i format.

byteArrayToLong

public static long byteArrayToLong(byte[] serverValue,
                                   int offset)
Convert the specified IBM i data type to a long.

Parameters:
serverValue - The array containing the data type in IBM i format.
offset - The offset into the byte array for the start of the IBM i value.
Returns:
a long corresponding to the data type.

bytesToString

public static final String bytesToString(byte[] b)
Convert the specified byte array to its hexadecimal String representation. Example generated string: "010203047E7F".

Parameters:
b - The array containing the data.
Returns:
A String containing the hex characters that represent the byte data.

bytesToString

public static final String bytesToString(byte[] b,
                                         int offset,
                                         int length)
Convert the specified byte array to its hexadecimal String representation. Example generated string: "010203047E7F".

Parameters:
b - The array containing the data.
offset - The offset into the array at which to begin reading bytes.
length - The number of bytes to read out of the array.
Returns:
A String containing the hex characters that represent the byte data.

stringToBytes

public static final byte[] stringToBytes(String s)
Convert the specified hexadecimal String into a byte array containing the byte values for the hexadecimal characters in the String. If the String contains characters other than those allowed for a hexadecimal String (0-9 and A-F), an exception will be thrown.

Parameters:
s - The String containing the hexadecimal representation of the data.
Returns:
A byte array containing the byte values of the hex characters.