private static void write(ByteBuffer buffer,
                              byte magic,
                              long timestamp,
                              ByteBuffer key,
                              ByteBuffer value,
                              CompressionType compressionType,
                              TimestampType timestampType) {
        try (DataOutputStream out = new DataOutputStream(new ByteBufferOutputStream(buffer))) {
            write(out, magic, timestamp, key, value, compressionType, timestampType);
        } catch (IOException e) {
            throw new KafkaException(e);
        }
    }
Write the header for a compressed record set in-place (i.e. assuming the compressed record data has already
been written at the value offset in a wrapped record). This lets you dynamically create a compressed message
set, and then go back later and fill in its size and CRC, which saves the need for copying to another buffer.

@param buffer The buffer containing the compressed record data positioned at the first offset of the
@param magic The magic value of the record set
@param recordSize The size of the record (including record overhead)
@param timestamp The timestamp of the wrapper record
@param compressionType The compression type used
@param timestampType The timestamp type of the wrapper record
clients/src/main/java/org/apache/kafka/common/record/LegacyRecord.java