@SuppressWarnings({"UnnecessaryFullyQualifiedName", "InstanceofIncompatibleInterface"})
  public static void visitDirectory(@NotNull Path directory, @Nullable Set<String> filter, @NotNull BiPredicate<Path, Result<BasicFileAttributes>> consumer)
  throws IOException, SecurityException {
    try (var dirStream = Files.newDirectoryStream(directory)) {
      for (var path : dirStream) {
        if (filter != null && !filter.contains(path.getFileName().toString())) {
          continue;
        }

        BasicFileAttributes attrs = null;
        if (path instanceof sun.nio.fs.BasicFileAttributesHolder) {
          attrs = ((sun.nio.fs.BasicFileAttributesHolder)path).get();
        }

        Result<BasicFileAttributes> result;
        if (attrs != null) {
          result = new Result<>(attrs);
        }
        else {
          try {
            result = new Result<>(NioFiles.readAttributes(path));
          }
          catch (IOException | RuntimeException e) {
            result = new Result<>(e);
          }
        }

        if (!consumer.test(path, result)) {
          break;
        }
      }
    }
  }
@SuppressWarnings({"UnnecessaryFullyQualifiedName", "InstanceofIncompatibleInterface"})
  public static void visitDirectory(@NotNull Path directory, @Nullable Set<String> filter, @NotNull BiPredicate<Path, Result<BasicFileAttributes>> consumer)