有没有一种方法可以避免必须将ByteBuffer中的byte []与ByteBuffer.get()操作复制。直接从ByteBuffer转到字符串,但没有中间字节[]?
我一直在寻找这个职位Java: Converting String to and from ByteBuffer and associated problems
,并导致中介CharBuffer的,我不想为好。
我希望它从ByteBuffer转到String。
当我知道我有一个byte []底层,这是很容易的代码,像这样
new String(data, offset, length, charSet);
我希望与ByteBuffer的类似的东西。我开始认为这可能是不可能的?我需要真正解码ByteBuffer的N个字节。
这可能有些不成熟的优化,但我真的只是好奇,想要测试性能和挤出每一点点。 (个人项目真的)。
感谢, 院长
你的意思是[ByteBuffer.array()](https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#array%28%29)? – user3159253