ByteBuffer在GWT中的字符串 [英] ByteBuffer to String in GWT
问题描述
在 PlayN 项目中,我拥有以下Java代码
import com.google.common.base.Charsets;
import java.nio.ByteBuffer;
ByteBuffer msg = ... //一个包含字符串的ByteBuffer
String s = Charsets.UTF_8.decode(msg).toString();
这在Java中工作正常,但是当我尝试使用GWT进行编译时,我得到:
方法decode(ByteBuffer)对于Charset类型是未定义的
在GWT中,获得一个ByteBuffer内部的字符串(用UTF-8编码)的正确方法是什么?
在从 On a PlayN project I have the following Java code this works fine in Java, but when I try to compile it with GWT I get: What's the proper way, in GWT, to obtain a String (encoded in UTF-8) that's inside a ByteBuffer? You should be able to use 这篇关于ByteBuffer在GWT中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! ByteBuffer $ c $获取字节后,您应该能够使用
新字符串(字节,UTF-8)
c>作为字节[]
使用 ByteBuffer#get(byte [])
。
这个 String
构造函数以及 getBytes(String)
是为UTF-8和ISO-8859-1实现的。 import com.google.common.base.Charsets;
import java.nio.ByteBuffer;
ByteBuffer msg = ... // a ByteBuffer that contains a String
String s = Charsets.UTF_8.decode(msg).toString();
The method decode(ByteBuffer) is undefined for the type Charset
new String(bytes, "UTF-8")
after getting the bytes out of the ByteBuffer
as a byte[]
using ByteBuffer#get(byte[])
.
This String
constructor, along with getBytes(String)
, is implemented for UTF-8 and ISO-8859-1.