Does anyone know how to convert ByteBuffer to byte[] array? I need to get byte array from my ByteBuffer
. When I run bytebuffer.hasArrray()
it returns no. Every question I looked so far is converting byte array to byteBuffer, but I need it other way around.
Thank you.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
If
hasArray()
reportsfalse
then, callingarray()
will throw an exception.In that case, the only way to get the data in a
byte[]
is to allocate abyte[]
and copy the bytes to thebyte[]
usingget(byte)
or similar.ByteBuffer
exposes the bulkget(byte[])
method which transfers bytes from the buffer into the array. You'll need to instantiate an array of length equal to the number of remaining bytes in the buffer.