0

I having an encoding issue. I have an android application that consists of a text field allowing a user to use a hebrew keyboard and key in hebrew characters.

I wish to encode this data according to the pc862 hebrew code page so that I may send it to a printer for printing (the printer is configured to accept data according to this code page). I should be able to do this with the following code:

String strData = new String(textData);
byte [] rawData = null;
try
{
    rawData = strData.getBytes("Cp862"); // Cp862: PC Hebrew
}
catch (UnsupportedEncodingException e)
{
    rawData = strData.getBytes();
}

According to the document found here, http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html

I should be able to encode this code page. However, the code keeps throwing the UnsupportedEncodingException. I am using java se 7 and jre 7, and have imported java.io. I am not sure why this is. I have tried the other code pages on this document and of the ones I have tried, most of them encode correctly.

Do anyone have any ideas what I am doing wrong? Any insight would be much appreciated.

erakitin
  • 11,437
  • 5
  • 44
  • 49
user1313973
  • 11
  • 1
  • 3
  • Is it failing on Java SE or in Android? I wouldn't be surprised if Android was missing many encodings in the SE spec; if that was the case you would probably want to roll your own (or find source you can use for an) encoding of the standard to include with your Android app. – antlersoft Jul 19 '12 at 16:33
  • In android. I thought the same thing, that maybe it was Android support problem. I hear there are ways to create your own encoding, is there any documentation on doing this that you could point to? It sounds like a lot of work. – user1313973 Jul 19 '12 at 16:57

3 Answers3

1

Have you tried using the name "IBM862" instead?

If I run the following code:

public static void main(String[] args) {
    Map<String, Charset> avmap = Charset.availableCharsets();
    for(String name : avmap.keySet()) {
        System.out.println("Charset: "+avmap.get(name));
    }
}

I get a list of available Charset names which includes "IBM862" but does not include Cp862. And according to the page to which you link, "IBM862" is the java.nio name for Cp862.

Bobulous
  • 12,967
  • 4
  • 37
  • 68
  • Thanks for that snippet of code. Now I now how to check for the available character sets. That's extremely helpful. However, it still does not encode. using getBytes("IBM862") still throws the unsupportedEncodingException – user1313973 Jul 23 '12 at 16:32
0

The default encoding (UTF-8) support Hebrew so why do you need CP862?

  • I wish I could use UTF-8, but the printer doesn't support it. It uses very old, rarely used codepages. Any other hebrew encodings I have tried with it have yielded jibberish when I print it. – user1313973 Jul 19 '12 at 16:55
0

I don't know about licensing restrictions for your app, but GNU Classpath has such an encoder and the source is of course available. You could include this in your own application (license permitting, of course).

antlersoft
  • 14,636
  • 4
  • 35
  • 55