Character data is converted through the AS400Text class. This class converts character data between an EBCDIC code page and character set (CCSID), and Unicode.
When the AS400Text object is constructed, the Java™ program specifies the length of the string to be converted and the server CCSID or encoding. The CCSID of the Java program is assumed to be 13488 Unicode. The toBytes() method converts from Java form to byte array in iSeries™ format. The toObject() method converts from a byte array in iSeries format to Java format.
The AS400BidiTransform class provides layout transformations that allow the conversion of bidirectional text in iSeries format (after its conversion to Unicode) to bidirectional text in Java format, or from Java format to iSeries format. The default conversion is based on the CCSID of the job. To alter the direction and shaping of the text, specify a BidiStringType. Note that where IBM® Toolbox for Java objects perform the conversion internally, as in the DataArea class, the objects have a method to override the string type. For example, the DataArea class has addVetoableChangeListener() method that you can specify to listen for a veto changes to certain properties, including string type.
The following example assumes that a DataQueueEntry object returns text in EBCDIC. The example converts the EBCDIC data to Unicode, so that the Java program can use data:
// Assume the data queue work has already been done to // retrieve the text from the iSeries and the data has been // put in the following buffer. int textLength = 100; byte[] data = new byte[textLength]; // Create a converter for the iSeries data type. Note a default // converter is being built. This converter assumes the iSeries // EBCDIC code page matches the client's locale. If this is not // true the Java program can explicitly specify the EBCDIC // CCSID to use. However, it is recommended that you specify a // CCSID whenever possible (see the Notes: below). AS400Text textConverter = new AS400Text(textLength) // Note: Optionally, you can create a converter for a specific // CCSID. Use an AS400 object in case the program is running // as an IBM Toolbox for Java proxy client. int ccsid = 37; AS400 system = ...; // AS400 object AS400Text textConverter = new AS400Text(textLength, ccsid, system); // Note: You can also create a converter with just the AS400 object. // This converter assumes the iSeries code page matches // the CCSID returned by the AS400 object. AS400Text textConverter = new AS400Text(textLength, system); // Convert the data from EBCDIC to Unicode. If the length of // the AS400Text object is longer than the number of // converted characters, the resulting String will be // blank-padded out to the specified length. String javaText = (String) textConverter.toObject(data);