private Path resolvePathFromEvent(WatchEvent<?> watchEvent, Path contextPath) {
        final Kind<?> kind = watchEvent.kind();
        /*
         * Can't simply continue when it detects that an event maybe ignored.
         */
        if (kind == StandardWatchEventKinds.OVERFLOW) {
            LOGGER.error("An event is unclear and lost");
            /*
             * TODO: should we do a full scan to avoid lost events?
             */
            return null;
        }
        final WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent;
        final Path eventPath = watchEventPath.context();
        /*
         * Must resolve, otherwise we can't get the file attributes.
         */
        return contextPath.resolve(eventPath);
    }
Watch directory, if new valid files are created, create instance correspondingly.
inlong-agent/agent-plugins/src/main/java/org/apache/inlong/agent/plugin/task/logcollection/local/FileTask.java