EBCDIC ascii conversion?

Discussion in 'Java' started by Sylvain, Jun 13, 2004.

  1. Sylvain

    Sylvain Guest

    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
     
    Sylvain, Jun 13, 2004
    #1
    1. Advertising

  2. Sylvain

    Roedy Green Guest

    On Sun, 13 Jun 2004 17:57:33 -0400, "Sylvain" <>
    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.
     
    Roedy Green, Jun 14, 2004
    #2
    1. Advertising

  3. 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
     
    Thomas Weidenfeller, Jun 14, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    9
    Views:
    6,975
  2. mike hengins

    ASCII TO EBCDIC: how ?

    mike hengins, Aug 29, 2005, in forum: Java
    Replies:
    1
    Views:
    3,141
    Roedy Green
    Aug 30, 2005
  3. Re: detecting ASCII/EBCDIC

    , Sep 2, 2008, in forum: C Programming
    Replies:
    3
    Views:
    390
  4. Antoninus Twink

    Re: detecting ASCII/EBCDIC

    Antoninus Twink, Sep 2, 2008, in forum: C Programming
    Replies:
    2
    Views:
    342
    Richard
    Sep 3, 2008
  5. Keith Thompson

    Re: detecting ASCII/EBCDIC

    Keith Thompson, Sep 3, 2008, in forum: C Programming
    Replies:
    2
    Views:
    329
    Keith Thompson
    Sep 3, 2008
Loading...

Share This Page