public int writeFullyTo(GatheringByteChannel channel) throws IOException {
        buffer.mark();
        int written = 0;
        while (written < sizeInBytes())
            written += channel.write(buffer);
        buffer.reset();
        return written;
    }
Write all records to the given channel (including partial records).
@param channel The channel to write to
@return The number of bytes written
@throws IOException For any IO errors writing to the channel
clients/src/main/java/org/apache/kafka/common/record/MemoryRecords.java