com.ibm.jtopenlite
Class Conv

java.lang.Object
  extended by com.ibm.jtopenlite.Conv

public final class Conv
extends Object

Utility class for converting data from one format to another.


Method Summary
static byte[] blankPadEBCDIC10(String s)
          Converts the specified String into a total of ten CCSID 37 bytes, blank padding with EBCDIC 0x40 as necessary.
static double byteArrayToDouble(byte[] data, int offset)
          Converts the specified bytes into a double value.
static float byteArrayToFloat(byte[] data, int offset)
          Converts the specified bytes into a float value.
static int byteArrayToInt(byte[] data, int offset)
          Converts the specified bytes into an int value.
static long byteArrayToLong(byte[] data, int offset)
          Converts the specified bytes into a long value.
static short byteArrayToShort(byte[] data, int offset)
          Converts the specified bytes into a short value.
static String bytesToHexString(byte[] data, int offset, int length)
          Converts the specified bytes into their hexadecimal String representation.
static String bytesToHexString(byte[] data, int offset, int length, char[] buffer)
          Converts the specified bytes into their hexadecimal String representation.
static String decfloat16ByteArrayToString(byte[] data, int offset)
          Converts the specified 8 bytes in decfloat16 format into a String.
static String decfloat34ByteArrayToString(byte[] data, int offset)
          Converts the specified 16 bytes in decfloat34 format into a String.
static byte[] doubleToByteArray(double d)
          Converts the specified double value into 8 bytes.
static void doubleToByteArray(double d, byte[] data, int offset)
          Converts the specified double value into 8 bytes.
static void doubleToPackedDecimal(double d, byte[] data, int offset, int numDigits, int scale)
           
static byte[] doubleToPackedDecimal(double d, int numDigits, int scale)
           
static void doubleToZonedDecimal(double d, byte[] data, int offset, int numDigits, int scale)
           
static byte[] doubleToZonedDecimal(double d, int numDigits, int scale)
           
static String ebcdicByteArrayToString(byte[] data, char[] buffer)
           
static String ebcdicByteArrayToString(byte[] data, int offset, int length)
          Converts the specified CCSID 37 bytes into a String.
static String ebcdicByteArrayToString(byte[] data, int offset, int length, char[] buffer)
          Converts the specified CCSID 37 bytes into a String.
static String ebcdicByteArrayToString(byte[] data, int offset, int length, char[] buffer, int ccsid)
          Converts the specific CCSID bytes into a String.
static String ebcdicByteArrayToString(byte[] data, int offset, int length, int ccsid)
          Converts the specific CCSID bytes into a String.
static byte[] floatToByteArray(float f)
          Converts the specified float value into 4 bytes.
static void floatToByteArray(float f, byte[] data, int offset)
          Converts the specified float value into 4 bytes.
static byte[] hexStringToBytes(String value)
          Converts the specified hexadecimal String into its constituent byte values.
static int hexStringToBytes(String value, byte[] data, int offset)
          Converts the specified hexadecimal String into its constituent byte values.
static byte[] intToByteArray(int value)
          Converts the specified int value into 4 bytes.
static void intToByteArray(int value, byte[] data, int offset)
          Converts the specified int value into 4 bytes.
static boolean isSupported(int ccsid)
          Returns true if the conversion to or from the specific CCSID is supported by the methods on this class.
static byte[] longToByteArray(long longValue)
          Converts the specified long value into 8 bytes.
static void longToByteArray(long longValue, byte[] data, int offset)
          Converts the specified long value into 8 bytes.
static double packedDecimalToDouble(byte[] data, int offset, int numDigits, int scale)
           
static String packedDecimalToString(byte[] data, int offset, int numDigits, int scale)
          Converts the specified packed decimal bytes into a String.
static String packedDecimalToString(byte[] data, int offset, int numDigits, int scale, char[] buffer)
          Converts the specified packed decimal bytes into a String.
static void shortToByteArray(int value, byte[] data, int offset)
          Converts the specified short value into 2 bytes.
static void stringToBlankPadEBCDICByteArray(String s, byte[] data, int offset, int length)
          Converts the specified String into CCSID 37 bytes, padding the byte array with EBCDIC spaces (0x40) up to length bytes.
static void stringToBlankPadEBCDICByteArray(String s, byte[] data, int offset, int length, int ccsid)
          Converts the specified String into bytes for the specified CCSID, padding the byte array with spaces up to length bytes.
static void stringToBlankPadUnicodeByteArray(String s, byte[] data, int offset, int length)
          Converts the specified String into Unicode bytes, padding the byte array with Unicode spaces (0x0020) up to length bytes.
static int stringToEBCDICByteArray(String s, byte[] data, int offset, int ccsid)
          Converts the specified String into the appropriate byte values for the specified CCSID.
static byte[] stringToEBCDICByteArray(String s, int ccsid)
          Converts the specified String into the appropriate byte values for the specified CCSID.
static int stringToEBCDICByteArray(String s, int length, byte[] data, int offset, int ccsid)
          Converts the specified String into the appropriate byte values for the specified CCSID.
static byte[] stringToEBCDICByteArray37(String s)
          Converts the specified String into CCSID 37 bytes.
static int stringToEBCDICByteArray37(String s, byte[] data, int offset)
          Converts the specified String into CCSID 37 bytes.
static int stringToEBCDICByteArray37(String s, int length, byte[] data, int offset)
           
static byte[] stringToPackedDecimal(String s, int numDigits)
          Converts the specified String (number) into packed decimal bytes.
static void stringToPackedDecimal(String s, int numDigits, byte[] buffer, int offset)
          Converts the specified String (number) into packed decimal bytes.
static byte[] stringToUnicodeByteArray(String s)
          Converts the specified String into Unicode bytes.
static int stringToUnicodeByteArray(String s, byte[] data, int offset)
          Converts the specified String into Unicode bytes.
static void stringToUnicodeByteArray(String s, byte[] data, int offset, int byteLength)
           
static int stringToUnicodeByteArray(String s, int length, byte[] data, int offset)
           
static int stringToUtf8ByteArray(String s, int length, byte[] data, int offset)
           
static byte[] stringToZonedDecimal(String s, int numDigits)
          Converts the specified String (number) into zoned decimal bytes.
static void stringToZonedDecimal(String s, int numDigits, byte[] buffer, int offset)
          Converts the specified String (number) into zoned decimal bytes.
static String unicodeByteArrayToString(byte[] data, int offset, int length)
          Converts the specified Unicode bytes into a String.
static String unicodeByteArrayToString(byte[] data, int offset, int length, char[] buffer)
          Converts the specified Unicode bytes into a String.
static double zonedDecimalToDouble(byte[] data, int offset, int numDigits, int scale)
           
static String zonedDecimalToString(byte[] data, int offset, int numDigits, int scale)
          Converts the specified zoned decimal bytes into a String.
static String zonedDecimalToString(byte[] data, int offset, int numDigits, int scale, char[] buffer)
          Converts the specified zoned decimal bytes into a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bytesToHexString

public static final String bytesToHexString(byte[] data,
                                            int offset,
                                            int length)
Converts the specified bytes into their hexadecimal String representation.


bytesToHexString

public static final String bytesToHexString(byte[] data,
                                            int offset,
                                            int length,
                                            char[] buffer)
Converts the specified bytes into their hexadecimal String representation.


hexStringToBytes

public static final byte[] hexStringToBytes(String value)
Converts the specified hexadecimal String into its constituent byte values.


hexStringToBytes

public static final int hexStringToBytes(String value,
                                         byte[] data,
                                         int offset)
Converts the specified hexadecimal String into its constituent byte values.


stringToEBCDICByteArray37

public static final byte[] stringToEBCDICByteArray37(String s)
Converts the specified String into CCSID 37 bytes.


stringToEBCDICByteArray37

public static final int stringToEBCDICByteArray37(String s,
                                                  byte[] data,
                                                  int offset)
Converts the specified String into CCSID 37 bytes.


stringToEBCDICByteArray37

public static final int stringToEBCDICByteArray37(String s,
                                                  int length,
                                                  byte[] data,
                                                  int offset)

stringToEBCDICByteArray

public static final byte[] stringToEBCDICByteArray(String s,
                                                   int ccsid)
                                            throws UnsupportedEncodingException
Converts the specified String into the appropriate byte values for the specified CCSID.

Throws:
UnsupportedEncodingException - Thrown if conversion to or from the specified CCSID is not supported.

stringToEBCDICByteArray

public static final int stringToEBCDICByteArray(String s,
                                                byte[] data,
                                                int offset,
                                                int ccsid)
                                         throws UnsupportedEncodingException
Converts the specified String into the appropriate byte values for the specified CCSID.

Throws:
UnsupportedEncodingException - Thrown if conversion to or from the specified CCSID is not supported.

stringToEBCDICByteArray

public static final int stringToEBCDICByteArray(String s,
                                                int length,
                                                byte[] data,
                                                int offset,
                                                int ccsid)
                                         throws UnsupportedEncodingException
Converts the specified String into the appropriate byte values for the specified CCSID.

Throws:
UnsupportedEncodingException - Thrown if conversion to or from the specified CCSID is not supported.

stringToUnicodeByteArray

public static final byte[] stringToUnicodeByteArray(String s)
Converts the specified String into Unicode bytes. returns the number of bytes.


stringToUnicodeByteArray

public static final int stringToUnicodeByteArray(String s,
                                                 byte[] data,
                                                 int offset)
Converts the specified String into Unicode bytes.


stringToUnicodeByteArray

public static final int stringToUnicodeByteArray(String s,
                                                 int length,
                                                 byte[] data,
                                                 int offset)

stringToUnicodeByteArray

public static void stringToUnicodeByteArray(String s,
                                            byte[] data,
                                            int offset,
                                            int byteLength)

stringToUtf8ByteArray

public static final int stringToUtf8ByteArray(String s,
                                              int length,
                                              byte[] data,
                                              int offset)

stringToBlankPadUnicodeByteArray

public static final void stringToBlankPadUnicodeByteArray(String s,
                                                          byte[] data,
                                                          int offset,
                                                          int length)
Converts the specified String into Unicode bytes, padding the byte array with Unicode spaces (0x0020) up to length bytes.


unicodeByteArrayToString

public static final String unicodeByteArrayToString(byte[] data,
                                                    int offset,
                                                    int length)
Converts the specified Unicode bytes into a String. The length is in bytes, and should be twice the length of the returned String.


unicodeByteArrayToString

public static final String unicodeByteArrayToString(byte[] data,
                                                    int offset,
                                                    int length,
                                                    char[] buffer)
Converts the specified Unicode bytes into a String. The length is in bytes, and should be twice the length of the returned String.


stringToBlankPadEBCDICByteArray

public static final void stringToBlankPadEBCDICByteArray(String s,
                                                         byte[] data,
                                                         int offset,
                                                         int length)
Converts the specified String into CCSID 37 bytes, padding the byte array with EBCDIC spaces (0x40) up to length bytes.


stringToBlankPadEBCDICByteArray

public static final void stringToBlankPadEBCDICByteArray(String s,
                                                         byte[] data,
                                                         int offset,
                                                         int length,
                                                         int ccsid)
                                                  throws UnsupportedEncodingException
Converts the specified String into bytes for the specified CCSID, padding the byte array with spaces up to length bytes.

Throws:
UnsupportedEncodingException - Thrown if conversion to or from the specified CCSID is not supported.

ebcdicByteArrayToString

public static final String ebcdicByteArrayToString(byte[] data,
                                                   int offset,
                                                   int length)
Converts the specified CCSID 37 bytes into a String. Note: You might as well just use new String(data,"Cp037") to avoid the extra char array this method needs to create. Note: You cannot use new String(data,"Cp037" because this is not supported on all JVMS


ebcdicByteArrayToString

public static final String ebcdicByteArrayToString(byte[] data,
                                                   char[] buffer)

ebcdicByteArrayToString

public static final String ebcdicByteArrayToString(byte[] data,
                                                   int offset,
                                                   int length,
                                                   char[] buffer)
Converts the specified CCSID 37 bytes into a String.


ebcdicByteArrayToString

public static final String ebcdicByteArrayToString(byte[] data,
                                                   int offset,
                                                   int length,
                                                   int ccsid)
                                            throws UnsupportedEncodingException
Converts the specific CCSID bytes into a String.

Throws:
UnsupportedEncodingException - Thrown if conversion to or from the specified CCSID is not supported.

ebcdicByteArrayToString

public static final String ebcdicByteArrayToString(byte[] data,
                                                   int offset,
                                                   int length,
                                                   char[] buffer,
                                                   int ccsid)
                                            throws UnsupportedEncodingException
Converts the specific CCSID bytes into a String.

Throws:
UnsupportedEncodingException - Thrown if conversion to or from the specified CCSID is not supported.

isSupported

public static boolean isSupported(int ccsid)
Returns true if the conversion to or from the specific CCSID is supported by the methods on this class.


byteArrayToLong

public static final long byteArrayToLong(byte[] data,
                                         int offset)
Converts the specified bytes into a long value.


byteArrayToInt

public static final int byteArrayToInt(byte[] data,
                                       int offset)
Converts the specified bytes into an int value.


byteArrayToShort

public static final short byteArrayToShort(byte[] data,
                                           int offset)
Converts the specified bytes into a short value.


shortToByteArray

public static final void shortToByteArray(int value,
                                          byte[] data,
                                          int offset)
Converts the specified short value into 2 bytes.


intToByteArray

public static final byte[] intToByteArray(int value)
Converts the specified int value into 4 bytes.


intToByteArray

public static final void intToByteArray(int value,
                                        byte[] data,
                                        int offset)
Converts the specified int value into 4 bytes.


longToByteArray

public static final byte[] longToByteArray(long longValue)
Converts the specified long value into 8 bytes.


longToByteArray

public static final void longToByteArray(long longValue,
                                         byte[] data,
                                         int offset)
Converts the specified long value into 8 bytes.


blankPadEBCDIC10

public static final byte[] blankPadEBCDIC10(String s)
Converts the specified String into a total of ten CCSID 37 bytes, blank padding with EBCDIC 0x40 as necessary.


byteArrayToFloat

public static final float byteArrayToFloat(byte[] data,
                                           int offset)
Converts the specified bytes into a float value.


floatToByteArray

public static final void floatToByteArray(float f,
                                          byte[] data,
                                          int offset)
Converts the specified float value into 4 bytes.


floatToByteArray

public static final byte[] floatToByteArray(float f)
Converts the specified float value into 4 bytes.


byteArrayToDouble

public static final double byteArrayToDouble(byte[] data,
                                             int offset)
Converts the specified bytes into a double value.


doubleToByteArray

public static final void doubleToByteArray(double d,
                                           byte[] data,
                                           int offset)
Converts the specified double value into 8 bytes.


doubleToByteArray

public static final byte[] doubleToByteArray(double d)
Converts the specified double value into 8 bytes.


decfloat16ByteArrayToString

public static final String decfloat16ByteArrayToString(byte[] data,
                                                       int offset)
Converts the specified 8 bytes in decfloat16 format into a String.


decfloat34ByteArrayToString

public static final String decfloat34ByteArrayToString(byte[] data,
                                                       int offset)
Converts the specified 16 bytes in decfloat34 format into a String.


packedDecimalToString

public static final String packedDecimalToString(byte[] data,
                                                 int offset,
                                                 int numDigits,
                                                 int scale)
Converts the specified packed decimal bytes into a String.


packedDecimalToString

public static final String packedDecimalToString(byte[] data,
                                                 int offset,
                                                 int numDigits,
                                                 int scale,
                                                 char[] buffer)
Converts the specified packed decimal bytes into a String. The number of bytes used from data is equal to numDigits/2+1.


packedDecimalToDouble

public static final double packedDecimalToDouble(byte[] data,
                                                 int offset,
                                                 int numDigits,
                                                 int scale)

doubleToPackedDecimal

public static final byte[] doubleToPackedDecimal(double d,
                                                 int numDigits,
                                                 int scale)

doubleToPackedDecimal

public static final void doubleToPackedDecimal(double d,
                                               byte[] data,
                                               int offset,
                                               int numDigits,
                                               int scale)

stringToPackedDecimal

public static final byte[] stringToPackedDecimal(String s,
                                                 int numDigits)
Converts the specified String (number) into packed decimal bytes.


stringToPackedDecimal

public static final void stringToPackedDecimal(String s,
                                               int numDigits,
                                               byte[] buffer,
                                               int offset)
Converts the specified String (number) into packed decimal bytes. The string must have the correct number of decimal digits for the conversion to be correct.


zonedDecimalToString

public static final String zonedDecimalToString(byte[] data,
                                                int offset,
                                                int numDigits,
                                                int scale)
Converts the specified zoned decimal bytes into a String.


zonedDecimalToString

public static final String zonedDecimalToString(byte[] data,
                                                int offset,
                                                int numDigits,
                                                int scale,
                                                char[] buffer)
Converts the specified zoned decimal bytes into a String.


zonedDecimalToDouble

public static final double zonedDecimalToDouble(byte[] data,
                                                int offset,
                                                int numDigits,
                                                int scale)

doubleToZonedDecimal

public static final byte[] doubleToZonedDecimal(double d,
                                                int numDigits,
                                                int scale)

doubleToZonedDecimal

public static final void doubleToZonedDecimal(double d,
                                              byte[] data,
                                              int offset,
                                              int numDigits,
                                              int scale)

stringToZonedDecimal

public static final byte[] stringToZonedDecimal(String s,
                                                int numDigits)
Converts the specified String (number) into zoned decimal bytes.


stringToZonedDecimal

public static final void stringToZonedDecimal(String s,
                                              int numDigits,
                                              byte[] buffer,
                                              int offset)
Converts the specified String (number) into zoned decimal bytes.