问题描述
我移植了一些Java代码,需要能够翻转( javax.nio.Buffer.flip()
)。
I am porting some of the java code and need to be able to flip (javax.nio.Buffer.flip()
).
我使用的字节[]来存储数据,我想为翻转这些字节数组,很像缓冲这样做,因为我相信下Buffer类使用字节[]为好。
I am using byte[] to store data, and I want to flip these byte array, much like Buffer does it, as I believe underneath Buffer class uses byte[] as well.
感谢
推荐答案
ByteBuffer的
可以使用字节[]
(从创建比方说, ByteBuffer.wrap
)或者非Java堆内存(使用 ByteBuffer.allocateDirect
创建)。你可以得到基本字节[]
与 ByteBuffer.array
。但在缓冲区调用翻转
和类似的方法并不chnage的实际数据。代替与所述数据相关联的偏移改变。因此,与相当于字节
是改变你的代码与它相关联的偏移量。
ByteBuffer
may use a byte[]
(create from, say, ByteBuffer.wrap
) or non-Java heap memory (created with ByteBuffer.allocateDirect
). You can get the underlying byte[]
with ByteBuffer.array
. But calling flip
and similar methods on buffers does not chnage the actual data. Instead offsets associated with the data are changed. So the equivalent with byte
would be to change the offsets that your code is associating with it.
这篇关于在C#中javax.nio.Buffer.flip()的等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!