Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > EBCDIC ascii conversion?

Reply
Thread Tools

EBCDIC ascii conversion?

 
 
Sylvain
Guest
Posts: n/a
 
      06-13-2004
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


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      06-14-2004
On Sun, 13 Jun 2004 17:57:33 -0400, "Sylvain" <(E-Mail Removed)>
wrote or quoted :

> 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.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-14-2004
Sylvain wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: detecting ASCII/EBCDIC Antoninus Twink C Programming 2 09-03-2008 09:02 AM
Re: detecting ASCII/EBCDIC Keith Thompson C Programming 2 09-03-2008 01:26 AM
Re: detecting ASCII/EBCDIC vippstar@gmail.com C Programming 3 09-02-2008 11:58 PM
ASCII TO EBCDIC: how ? mike hengins Java 1 08-30-2005 02:26 AM
Converting Pack/Unpacked EBCDIC file to ASCII kristenzhang@gmail.com Java 9 02-24-2005 05:31 PM



Advertisments