Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ebcdic to ascii

 
ryan wayne
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,

I am receiving a message from an as400 to win box so the message is in ebcdic
I have scoured forever for help and stumbles across this little ditty.
I would like to get an array of bytes and use this but
it is confusing to say the least. can some one show me an example of how this would be used?

thanks alot!

 
Dun Dagda
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps something like:

assuming the above code is in a proper class that has access to your Translate class, something like the above should work. You will then have a string of EBCDIC characters that you can use.

If I have misunderstood what you wanted, or written something stupid, please let me know.

DD
 
Dun Dagda
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, your method returns an int, I forgot to cast it to a byte before putting it in the array like this:


Sorry about that, :roll:
DD
 
Dun Dagda
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyway, looking more closely at the constructors of the String class in the Java API documentation, String has overloaded constructors that handle byte arrays in a specified charset, so it should be possible to do something like this:

to give you a string translated into EBCDIC, rather than use the Translate class that you found.

DD
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic