And*_*esQ 3 gwt bytebuffer playn
在PlayN项目中,我有以下 Java 代码
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();
Run Code Online (Sandbox Code Playgroud)
这在 Java 中运行良好,但是当我尝试使用 GWT 编译它时,我得到:
The method decode(ByteBuffer) is undefined for the type Charset
在 GWT 中,获取 ByteBuffer 中的字符串(以 UTF-8 编码)的正确方法是什么?
您应该能够使用new String(bytes, "UTF-8")获得的字节出来后ByteBuffer作为byte[]使用ByteBuffer#get(byte[])。
此String构造函数与 一起getBytes(String)为 UTF-8 和 ISO-8859-1 实现。
| 归档时间: |
|
| 查看次数: |
1305 次 |
| 最近记录: |