Any freeware java library to encode from Unicode to CP866?

1k Views Asked by At

I'm trying to print to a device which supports CP866 encoding only.

Unfortunately the device from which I'm printing (an Android device) does not support CP866, resulting in "abc".getBytes("CP866") throwing the UnsupportedEncodingException.

So, I guess, I have to do Unicode to CP866 encoding myself. Is there any freeware java library that does that?

4

There are 4 best solutions below

1
On BEST ANSWER

http://msdn.microsoft.com/en-us/goglobal/cc305166 has the list of characters; should no pre-made option work, writing code to iterate through an array translating Unicode characters to bytes suitable for CP866 shouldn't take much time at all.

0
On

I was needed to encode string with Cp866 in android. You can use java library with made up charset classes. Cp866 among them.

This is the link: http://www.doc.ic.ac.uk/~awl03/cgi-bin/trac.cgi/miro/browser/trunk/gcc/libjava/classpath/gnu/java/nio/charset

If you want extend Charset class and add you private Charset: Java NIO. Chapter 6 Character sets

5
On

According to the Oracle documentation, Cp866 is a supported encoding for Java 7. So either

  • you are using an old version of Java that doesn't support Cp866 (e.g. see @Joachim's comment!!!), or
  • the Java runtime is not recognizing the name you are using. (The canonical name for the charset is "Cp866" not "CP866".)

UPDATE - it is unlikely to be the latter. From what I can make out from the source, the charset lookup mechanism used by the standard "provider" is case insensitive.

References:

0
On

The class java.nio.charset.Charset supports both Cp866 and of course Unicode. I guess you could use that with the encode and decode methods.