I figured out the issue myself, so I'm writing it here on StackOverflow
to share the info and be useful for anyone else facing the same problem.
According to the java-doc for ByteBuffer.wrap()
:
The new buffer's capacity and limit will be
array.length
, its position will be zero, and its mark will be undefined.
And the java-doc for Buffer.flip()
says:
Flips this buffer. The limit is set to the current position and then the position is set to zero. If the mark is defined then it is discarded.
The answer is now clear: wrap()
sets the buffer's position to zero, and flip()
sets the buffer's limit to the current position (which is zero), and write(buffer)
will start from position to limit which are both 0
, thus it writes nothing!