private ByteBuffer getBuffer(int alignedSize) {
        assert WALUtil.isAligned(alignedSize);

        ByteBuffer currentBuf = threadLocalByteBuffer.get();
        if (alignedSize <= currentBuf.capacity()) {
            return currentBuf;
        }
        if (maxTempBufferSize > 0 && alignedSize > maxTempBufferSize) {
            throw new RuntimeException("too large write size");
        }

        ByteBuffer newBuf = DirectIOUtils.allocateForDirectIO(directIOLib, alignedSize);
        threadLocalByteBuffer.set(newBuf);
        DirectIOUtils.releaseDirectBuffer(currentBuf);
        return newBuf;
    }
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