private void unalignedWrite(ByteBuf src, long position) throws IOException {
        long start = position;
        long end = position + src.readableBytes();
        long alignedStart = WALUtil.alignSmallByBlockSize(start);
        long alignedEnd = WALUtil.alignLargeByBlockSize(end);
        int alignedSize = (int) (alignedEnd - alignedStart);

        // read the data in the range [alignedStart, alignedEnd) to tmpBuf
        ByteBuffer tmpBuf = getBuffer(alignedSize);
        tmpBuf.position(0).limit(alignedSize);
        read(tmpBuf, alignedStart);

        // overwrite the data in the range [start, end) in tmpBuf
        for (ByteBuffer buffer : src.nioBuffers()) {
            tmpBuf.position((int) (start - alignedStart));
            start += buffer.remaining();
            tmpBuf.put(buffer);
        }
        tmpBuf.position(0).limit(alignedSize);

        // write it
        write(tmpBuf, alignedStart);
    }
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