Tags: class, convert, decimal, encoded, encoding, encoing, essentials, file, following, format, hexa, ibm437, java, string, value, write
Java Encoding
On Java Studio » Java Essentials
2,004 words with 6 Comments; publish: Mon, 24 Sep 2007 10:46:00 GMT; (15078.13, « »)
I want a small class which can do the following
- convert a hexa decimal value into IBM437 encoing format
- write that encoded string into a file
- again read that file and convert the encoded value back to hexadecimal format.
I was able to do till the second step. But decoding the value back and putting it into hex format is not working for me.....Any help pls....
http://javaessentials.developerfaqs.com/q_java-essentials_40330.html
All Comments
Leave a comment...
- 6 Comments

- use "0x" + Integer.toHexString(int)#1; Fri, 13 Jul 2007 03:00:00 GMT

- What is : IBM437 encoing format please ? I was tolde to use str.replaceAll("\\P{ASCII}+", "") to get a String free of all non-ASCII chars . do you know how to get an array of all ASCII chars plz#2; Fri, 13 Jul 2007 03:00:00 GMT

In Java, if it's encoded it's not a string, but a sequence of bytes. Your specification is rather confusing.
Do you mean you start with an hexedecimal representation of some bytes which are in IBM437 encoding? Or are you converting a number, or byte array, into a string of characters 0-9, A-F and then encoding them into an IBM437 encoded byte sequence?
Converting a stream of bytes to hex is the same whatever characters they might happen to represent in some encoding.
#3; Fri, 13 Jul 2007 03:00:00 GMT

I am creating a byte array from a set hexadecimal values. This byte array am encoding into a sting using IBM-437 format. Am using IBM-437 since I have extended ASCII characters. This encoded string is written into a database or a file. Again I will read it back from the file and decode and display
#4; Fri, 13 Jul 2007 03:00:00 GMT

- How do you write it so a database? Instances of String (in java) are always unicode internally.Kaj#5; Fri, 13 Jul 2007 03:00:00 GMT

I'd suggest you pick up the "codec" package from apache commons (jatarka.apache.org/commons) to convert from a string of hex to a byte array.
Once you have a byte array you just need to use the constructor for String which takes a byte array and the name of the encoding. I don't know which name Java uses for your particular encoding but there's quite a wide selection, especially if you get the International version.
#6; Fri, 13 Jul 2007 03:00:00 GMT