I am porting some of the java code and need to be able to flip (javax.nio.Buffer.flip()
).
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.
Thanks
There's no direct equivalent of the
java.nio
package in .NET. Asynchronous IO is usually handled withStream.BeginRead
/EndRead
, but it's not really the same model. Could you tell us what you're trying to do?EDIT: You've now provided the low-level details of what you're trying to do, but as there's no real equivalent for the
nio
classes in .NET, you'll either have to write them yourself (not impossible, but a pain) or use a different higher level type. You might be able to useMemoryStream
for example - write into it, then seek back to the start. That's a bit like flipping a byte buffer. However, we can't tell whether or not that's appropriate without more information as to the higher-level goal. There may be a much better way of doing it.ByteBuffer
may use abyte[]
(create from, say,ByteBuffer.wrap
) or non-Java heap memory (created withByteBuffer.allocateDirect
). You can get the underlyingbyte[]
withByteBuffer.array
. But callingflip
and similar methods on buffers does not chnage the actual data. Instead offsets associated with the data are changed. So the equivalent withbyte
would be to change the offsets that your code is associating with it.