1// ...populate the buffer...
2buffer.flip(); // flip the buffer for reading
3byte[] bytes = new byte[buffer.remaining()]; // create a byte array the length of the number of bytes written to the buffer
4buffer.get(bytes); // read the bytes that were written
5String packet = new String(bytes);
6