EBCDIC ascii conversion?

S

Sylvain

Hello,
----------------------------------------------------------------------------
--------------------------------
I am trying to encode/decode unicode to/from ebcdic character string. When I
try the following:

String sEbcdic = "1234567890abcdefghijklmnopqurstuvwxyz";
String sReencodedEbcdic = null;
try {
String sReturnEbcdic = (new String(new String(sEbcdic.getBytes(),
"8859_1").
getBytes("cp037")));
sReencodedEbcdic = (new String(new String(sReturnEbcdic.getBytes(),
"cp037").getBytes("8859_1")));
System.out.println(sReencodedEbcdic);
}
catch (java.io.UnsupportedEncodingException e) {}

----------------------------------------------------------------------------
--------------------------------

I am getting the following output:

1234567890bcdefghijklmnopqurstuvwxyz

The 'a' character is not converted back!

Anyone ever had this problem?

Thanks

Sylvain
 
R

Roedy Green

String sEbcdic = "1234567890abcdefghijklmnopqurstuvwxyz";
String sReencodedEbcdic = null;
try {
String sReturnEbcdic = (new String(new String(sEbcdic.getBytes(),
"8859_1").
getBytes("cp037")));
sReencodedEbcdic = (new String(new String(sReturnEbcdic.getBytes(),
"cp037").getBytes("8859_1")));
System.out.println(sReencodedEbcdic);
}

Here's how I would write that code:

import java.io.UnsupportedEncodingException;

public class EbcdicTest
{

/**
* test harness
*
* @param args not used
*/
public static void main ( String[] args ) throws
UnsupportedEncodingException
{
// System 390 EBCDIC
String encoding = "Cp1047";

// microsoft proprietary USA
// encoding = "Cp037";

// IBM PC OEM DOS
// encoding = "Cp437";

String unicode = "1234567890abcdefghijklmnopqrstuvwxyz";
byte[] ebcdic = unicode.getBytes( encoding );
String reconsituted = new String( ebcdic, encoding );
System.out.println( unicode );
System.out.println( reconsituted );
}
}


It works fine with all three encodings.
 
T

Thomas Weidenfeller

Sylvain said:
The 'a' character is not converted back!

Run a debugger and check every intermediate result. Once you know which
of the conversions went wrong, check Sun's bug parade if this is a known
bug.

If you use an old VM, upgrade to the latest (released) VM. Try again. If
the problem is still there, if you have isolated it to one method, file
a bug report with Sun, and provide a demo program.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top