UTF-8 to EBCDIC in Java

Raj Mohan picture Raj Mohan · Apr 21, 2009 · Viewed 28.6k times · Source

Our requirement is to send EBCDIC text to mainframe. We have some chinese characters thus UTF8 format. So, is there a way to convert the UTF-8 characters to EBCDIC?

Thanks, Raj Mohan

Answer

Lawrence Dol picture Lawrence Dol · Apr 21, 2009

Assuming your target system is an IBM mainframe or midrange, it has full support for all of the EBCDIC encodings built into it's JVM as encodings named CPxxxx, corresponding to the IBM CCSID's (CP stands for code-page). You will need to do the translations on the host-side since the client side will not have the necessary encoding support.

Since Unicode is DBCS and greater, and supports every known character, you will likely be targeting multiple EBCDIC encodings; so you will likely configure those encodings in some way. Try to have your client Unicode (UTF-8, UTF-16, etc) only, with the translations being done as data arrives on the host and/or leaves the host system.

Other than needing to do translations host-side, the mechanics are the same as any Java translation; e.g. new String(bytes,encoding) and String.getBytes(encoding), and the various NIO and writer classes. There's really no magic - it's no different than translating between, say, ISO 8859-x and Unicode, or any other SBCS (or limited DBCS).

For example:

byte[] ebcdta="Hello World".getBytes("CP037");  // get bytes for EBCDIC codepage 37

You can find more information on IBM's documentation website.