public static List<Path> findFiles(String pattern, String... paths) throws IOException {
        if (pattern == null || pattern.isEmpty()) {
            throw new IllegalArgumentException("Non-empty pattern is required");
        } else if (pattern.startsWith("~/")) {
            return Collections
                    .singletonList(Paths.get(System.getProperty("user.home"), pattern.substring(2)).normalize());
        }

        if (!pattern.startsWith("glob:") && !pattern.startsWith("regex:")) {
            if (IS_WINDOWS) {
                final String reservedCharsWindows = "<>:\"|?*";
                pattern.chars().anyMatch(
                        value -> {
                            if (value < ' ' || reservedCharsWindows.indexOf(value) != -1) {
                                throw new IllegalArgumentException(String.format("File path contains reserved character <%s>", value));
                            }
                            return false;
                        }
                );
            }
            Path path = Paths.get(pattern);
            if (path.isAbsolute()) {
                return Collections.singletonList(path);
            } else {
                pattern = "glob:" + pattern;
            }
        }

        final Path searchPath;
        if (paths == null || paths.length == 0) {
            searchPath = Paths.get("");
        } else {
            String root = paths[0];
            Path rootPath = root.startsWith("~/")
                    ? Paths.get(System.getProperty("user.home"), root.substring(2)).normalize()
                    : Paths.get(root);
            searchPath = paths.length < 2 ? rootPath
                    : Paths.get(rootPath.toFile().getAbsolutePath(), Arrays.copyOfRange(paths, 1, paths.length))
                            .normalize();
        }

        final List<Path> files = new ArrayList<>();
        final PathMatcher matcher = FileSystems.getDefault().getPathMatcher(pattern);
        Files.walkFileTree(searchPath, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                if (matcher.matches(path)) {
                    files.add(path.normalize());
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc)
                    throws IOException {
                return FileVisitResult.CONTINUE;
            }
        });
        return files;
    }
Finds files according to the given pattern and path.

@param pattern non-empty pattern may or may have syntax prefix as in
               {@link java.nio.file.FileSystem#getPathMatcher(String)},
               defaults to {@code glob} syntax
@param paths   path to search, defaults to current work directory
@return non-null list of normalized absolute paths matching the pattern
@throws IOException when failed to find files
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseUtils.java