com.ibm.as400.access
Class BinaryConverter

java.lang.Object
  extended bycom.ibm.as400.access.BinaryConverter

public class BinaryConverter
extends Object

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


Method Summary
static double byteArrayToDouble(byte[] serverValue, int offset)
          Convert the specified server data type to a double.
static float byteArrayToFloat(byte[] serverValue, int offset)
          Convert the specified server data type to a float.
static int byteArrayToInt(byte[] serverValue, int offset)
          Convert the specified server data type to an int.
static long byteArrayToLong(byte[] serverValue, int offset)
          Convert the specified server data type to a long.
static short byteArrayToShort(byte[] serverValue, int offset)
          Convert the specified server data type to a short.
static long byteArrayToUnsignedInt(byte[] serverValue, int offset)
          Convert the specified server data type to a long.
static int byteArrayToUnsignedShort(byte[] serverValue, int offset)
          Convert the specified server 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 server format in the specified byte array.
static void doubleToByteArray(double doubleValue, byte[] serverValue, int offset)
          Convert the specified double into server format in the specified byte array.
static byte[] floatToByteArray(float floatValue)
          Convert the specified float into server format in the specified byte array.
static void floatToByteArray(float floatValue, byte[] serverValue, int offset)
          Convert the specified float into server 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 server format in the specified byte array.
static void intToByteArray(int intValue, byte[] serverValue, int offset)
          Convert the specified int into server format in the specified byte array.
static byte[] longToByteArray(long longValue)
          Convert the specified long into server format in the specified byte array.
static void longToByteArray(long longValue, byte[] serverValue, int offset)
          Convert the specified long into server format in the specified byte array.
static byte[] shortToByteArray(short shortValue)
          Convert the specified short into server format in the specified byte array.
static void shortToByteArray(short shortValue, byte[] serverValue, int offset)
          Convert the specified short into server 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 server format in the specified byte array.
static void unsignedIntToByteArray(long longValue, byte[] serverValue, int offset)
          Convert the specified long into server format in the specified byte array.
static byte[] unsignedShortToByteArray(int intValue)
          Convert the specified int into server format in the specified byte array.
static void unsignedShortToByteArray(int intValue, byte[] serverValue, int offset)
          Convert the specified int into server 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 server format in the specified byte array.

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

shortToByteArray

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

Parameters:
shortValue - The value to be converted to server format.
Returns:
The array with the data type in server format.

byteArrayToShort

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

Parameters:
serverValue - The array containing the data type in server format.
offset - The offset into the byte array for the start of the server 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 server format in the specified byte array.

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

intToByteArray

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

Parameters:
intValue - The value to be converted to server format.
Returns:
The array with the data type in server format.

byteArrayToInt

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

Parameters:
serverValue - The array containing the data type in server format.
offset - The offset into the byte array for the start of the server 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 server format in the specified byte array.

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

floatToByteArray

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

Convert the specified float into server format in the specified byte array.

Parameters:
floatValue - The value to be converted to server format.
Returns:
The array with the data type in server format.

floatToByteArray

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

Parameters:
floatValue - The value to be converted to server format.
Returns:
The array with the data type in server format.

byteArrayToFloat

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

Parameters:
serverValue - The array containing the data type in server format.
offset - The offset into the byte array for the start of the server 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 server format in the specified byte array.

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

doubleToByteArray

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

Parameters:
doubleValue - The value to be converted to server format.
Returns:
The array with the data type in server format.

byteArrayToDouble

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

Parameters:
serverValue - The array containing the data type in server format.
offset - The offset into the byte array for the start of the server 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 server format in the specified byte array.

Parameters:
intValue - The value to be converted to server 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 server format.
offset - The offset into the byte array for the start of the server value.

unsignedShortToByteArray

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

Parameters:
intValue - The value to be converted to server format. The integer should be greater than or equal to zero and representable in two bytes.
Returns:
The array with the data type in server format.

byteArrayToUnsignedShort

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

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

unsignedIntToByteArray

public static void unsignedIntToByteArray(long longValue,
                                          byte[] serverValue,
                                          int offset)
Convert the specified long into server format in the specified byte array.

Parameters:
longValue - The value to be converted to server 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 server format.
offset - The offset into the byte array for the start of the server value.

unsignedIntToByteArray

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

Parameters:
longValue - The value to be converted to server format. The long should be greater than or equal to zero and representable in four bytes.
Returns:
The array with the data type in server format.

byteArrayToUnsignedInt

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

Parameters:
serverValue - The array containing the data type in server format.
offset - The offset into the byte array for the start of the server 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 server format in the specified byte array.

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

longToByteArray

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

Parameters:
longValue - The value to be converted to server format.
Returns:
The array with the data type in server format.

byteArrayToLong

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

Parameters:
serverValue - The array containing the data type in server format.
offset - The offset into the byte array for the start of the server 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.

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.

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.