public static byte[] byteBufferToArray(ByteBuffer buf) {
        byte[] arr = new byte[buf.remaining()];
        int prevPosition = buf.position();
        try {
            buf.get(arr);
        } finally {
            buf.position(prevPosition);
        }
        return arr;
    }
Copy a byte buffer into an array.  This will not affect the buffer's
position or mark.
clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java