private int write(ByteBuffer src, long position) throws IOException {
        assert WALUtil.isAligned(src.remaining());

        int bytesWritten = 0;
        while (src.hasRemaining()) {
            int written = randomAccessFile.write(src, position + bytesWritten);
            // kdio will throw an exception rather than return -1, so we don't need to check for -1
            bytesWritten += written;
        }
        return bytesWritten;
    }
Create the file and set length if not exists, and check the file size if exists.
s3stream/src/main/java/com/automq/stream/s3/wal/util/WALBlockDeviceChannel.java