English 中文(简体)
Convert Erlang UTF-8 encoded string to java.lang. 努力
原标题:Convert Erlang UTF-8 encoded string to java.lang.String

The Java node received an Erlang string encoded in UTF-8. 其类别为<代码>。 OtpErlangString。 如果我仅作.toString(>.stringValue(>, 由此产生的java.lang.String 无效的代码点(基本上,与埃尔朗的地貌相比,每个星体都被视为不同特性)。

现在,我想在创建Java String时使用new String(bytes, “UTF-8”,但如何从中获取tes。 OtpErlangString?

问题回答

It s strange you get OtpErlangString on Java side when you use UTF8 characters. I get object of this type if I use ASCII characters only. If I add at least one UTF8 character, the resulting type is OtpErlangList (which is logical as strings are just lists of ints in Erlang) and then I can use its stringValue() method. So that after sending string form Erlang like:

(waco@host)8> {proc, java1@host} ! "ąćśźżęółńa".
[261,263,347,378,380,281,243,322,324,97]

On Java node 我收到并印刷了该文件:

OtpErlangList l = (OtpErlangList) mbox.receive();
System.out.println(l.stringValue());

产出正确:

ąćśźżęółńa

然而,如果你的情况不是这样,那么你会试图通过强迫OtpErlangList代表,例如,增加一个空洞的图象作为扼杀清单的第一个要素:

(waco@wborowiec)11> {proc, java1@wborowiec} ! [{}] ++ "ąćśźżęółńa".
[{},261,263,347,378,380,281,243,322,324,97]

Java一旁:

OtpErlangList l = (OtpErlangList) mbox.receive();
// get rid of an extra tuple
OtpErlangObject[] strArr = Arrays.copyOfRange(l.elements(), 1, l.elements().length);
OtpErlangList l2 = new OtpErlangList(strArr);
System.out.println(l2.stringValue());




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签