有沒有一種方法可以避免必須將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