After putting stuff into a Buffer, or reading stuff into it you have to flip the buffer to write or get the data from it. Check the flip()
method in the Buffer class. The docs say
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. After a sequence of channel-read or put operations, invoke this method to prepare for a sequence of channel-write or relative get operations.
So adding a buffer.flip() after the put should do the trick :)