public ByteBuffer toByteBuffer() {
    finishWriting();
    consolidateChunks();
    return buffer;
  }
gets the contents of this stream as a ByteBuffer, ready for reading. The stream should not be
written to past this point until it has been reset.
geode-serialization/src/main/java/org/apache/geode/internal/serialization/BufferDataOutputStream.java