Numeric conversionConversion classes for numeric data simply convert numeric data from AS/400 format to Java format. Supported types are shown in the following table:
The following example shows conversion from an AS/400 numeric type to a Java int: |
// Create a buffer to hold the AS/400 // type. Assume the buffer is filled // with numeric AS/400 data by data // queues, program call, etc. byte[] data = new byte[100]; // Create a converter for this // AS/400 data type. AS400Bin4 bin4Converter = new AS400Bin4(); // Convert from AS/400 type to Java // object. The number starts at the // beginning of the buffer. Integer intObject = (Integer) bin4Converter.toObject(data,0); // Extract the simple Java type from // the Java object. int i = intObject.intValue();
The following example shows conversion from a Java int to an AS/400 numeric data type: |
// Create a Java object that contains // the value to convert. Integer intObject = new Integer(22); // Create a converter for the AS/400 // data type. AS400Bin4 bin4Converter = new AS400Bin4(); // Convert from Java object to // AS/400 type. byte[] data = bin4Converter.toBytes(intObject); // Find out how many bytes of the // buffer were filled with the // AS/400 value. int length = bin4Converter.getByteLength();
[ Legal | AS/400 Glossary ] |