private int flushedSizeInBytes() {
        return batchOutput.position() - initialPosition;
    }
Check whether the batch has enough room for all the record values.

Returns an empty {@link OptionalInt} if the batch builder has room for this list of records.
Otherwise, it returns the expected number of bytes needed for a batch to contain these records.

@param records the records to use when checking for room
@param serializationCache serialization cache for computing sizes
@return empty {@link OptionalInt} if there is room for the records to be appended, otherwise
        returns the number of bytes needed
raft/src/main/java/org/apache/kafka/raft/internals/BatchBuilder.java