private static FileChannel openChannel(File file,
                                           boolean mutable,
                                           boolean fileAlreadyExists,
                                           int initFileSize,
                                           boolean preallocate) throws IOException {
        if (mutable) {
            if (fileAlreadyExists || !preallocate) {
                return FileChannel.open(file.toPath(), StandardOpenOption.CREATE, StandardOpenOption.READ,
                        StandardOpenOption.WRITE);
            } else {
                RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
                randomAccessFile.setLength(initFileSize);
                return randomAccessFile.getChannel();
            }
        } else {
            return FileChannel.open(file.toPath());
        }
    }
Open a channel for the given file
For windows NTFS and some old LINUX file system, set preallocate to true and initFileSize
with one value (for example 512 * 1025 *1024 ) can improve the kafka produce performance.
@param file File path
@param mutable mutable
@param fileAlreadyExists File already exists or not
@param initFileSize The size used for pre allocate file, for example 512 * 1025 *1024
@param preallocate Pre-allocate file or not, gotten from configuration.
clients/src/main/java/org/apache/kafka/common/record/FileRecords.java