Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,297 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,438 people online right now. Registration is fast and FREE... Join Now!




Advice on ASCII to EBCDIC conversion

 
Reply to this topicStart new topic

Advice on ASCII to EBCDIC conversion, How to proceed...

NickDMax
3 Sep, 2008 - 01:25 PM
Post #1

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
So I have to write some data files that use EBCDIC and I am excited!!! I have never actually used EBCDIC it is just one of these oddities that I just have never had a chance to use (since I don't do much mainframe work).

Anyway... My first though twas a hash table, but that turns out to be kind of ugly:
CODE
    static {
        Hashtable<Byte, Byte> ASCII2EBCDIC = new Hashtable<Byte, Byte>(256);
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x00), Byte.valueOf((byte)0x00));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x01), Byte.valueOf((byte)0x01));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x02), Byte.valueOf((byte)0x02));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x03), Byte.valueOf((byte)0x03));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x04), Byte.valueOf((byte)0x04));
    }

And I just see several things that are going to bug me (line byte to Byte and back again). However at this moment using a hash table seems about the best solution there is... I know there are some formulas for converting characters and digits -- but I don't think those work well for symbols.

Anyway, I was wondering if anyone had any advince on the matter.

I am planning on making a stream that I can put data in one and and get it back out the other end converted. This is so I can plug this right into the file io and hopefully write the data transparently converting form ASCII to EBCDIC.

I will make this a snippet once it is done.

This post has been edited by NickDMax: 3 Sep, 2008 - 01:26 PM
User is offlineProfile CardPM
+Quote Post

pbl
RE: Advice On ASCII To EBCDIC Conversion
3 Sep, 2008 - 03:54 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,110



Thanked: 202 times
Dream Kudos: 75
My Contributions
QUOTE(NickDMax @ 3 Sep, 2008 - 02:25 PM) *

So I have to write some data files that use EBCDIC and I am excited!!!


Whatever turns you on smile.gif

QUOTE

I have never actually used EBCDIC it is just one of these oddities that I just have never had a chance to use (since I don't do much mainframe work).

Probably that it is still used in the States... all othe languages have accented characters so I guess you will not found EBCDIC used anywhere else... it likes the old AM/PM concept that you will never find on any airline/train/invoice ticket anywhere else in the world



Anyway... My first though twas a hash table, but that turns out to be kind of ugly:
CODE
    
static {
        Hashtable<Byte, Byte> ASCII2EBCDIC = new Hashtable<Byte, Byte>(256);
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x00), Byte.valueOf((byte)0x00));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x01), Byte.valueOf((byte)0x01));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x02), Byte.valueOf((byte)0x02));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x03), Byte.valueOf((byte)0x03));
        ASCII2EBCDIC.put(Byte.valueOf((byte)0x04), Byte.valueOf((byte)0x04));
    }


Forget hastable for that, you are using a Cadillac to deliver a pizza
Just build an Array of equivalent characters indexed by the ASCII code will be a lot more efficient
At the limit, if you want to code, write an algorith to build the array that you will run only once at the object creation

This post has been edited by pbl: 3 Sep, 2008 - 03:57 PM
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Advice On ASCII To EBCDIC Conversion
3 Sep, 2008 - 06:01 PM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
QUOTE
Probably that it is still used in the States... all othe languages have accented characters so I guess you will not found EBCDIC used anywhere else...
Its a Canadian organization that I am using this with. Actually you will find that Mainframes tend to use this coding a good deal. ("legacy systems" is the dysphemism these days... even though that can refer to any thing from 5 to 100 years old). So lets not jump on this, "Oh, those goofy Americans and their ameri-centric character coding systems!" boat. smile.gif

Not to mention that EBCDIC is just as "code page" friendly as ASCII (well... maybe not "just as" since the characters are scrambled about). There is even a 2 character wide EBCDIC coding that looks like a Unicode-EBCDIC bastard child.

Anyway! Thanks for the Array idea! This is why I don't like working in Java, I always seem to do things the hard way, just to learn later that there was much easier way to do things.

This post has been edited by NickDMax: 3 Sep, 2008 - 06:03 PM
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Advice On ASCII To EBCDIC Conversion
4 Sep, 2008 - 04:33 AM
Post #4

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 11 times
My Contributions
The String class (and it's .getBytes(encoding) method) of most JDKs support it out of the box, just be careful, because the naming is not really standard according to some. An example
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Advice On ASCII To EBCDIC Conversion
4 Sep, 2008 - 05:23 AM
Post #5

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Yea I figured as much! That was why I asked here.

Trust me to go about it the long way again! Thanks
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:04AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month