@Override
  public List<FileMetadata> listFilesWithMetadata(URI fileUri, boolean recursive)
      throws IOException {
    File file = toFile(fileUri);
    if (!recursive) {
      return Arrays.stream(file.list()).map(s -> getFileMetadata(new File(file, s))).collect(Collectors.toList());
    } else {
      try (Stream<Path> pathStream = Files.walk(Paths.get(fileUri))) {
        return pathStream.filter(s -> !s.equals(file.toPath())).map(p -> getFileMetadata(p.toFile()))
            .collect(Collectors.toList());
      }
    }
  }
@Test
  public void testListFilesWithMetadata()
      throws IOException {
    LocalPinotFS localPinotFS = new LocalPinotFS();
    File tempDirPath = new File(_absoluteTmpDirPath, "test-list-files-with-md");
    Assert.assertTrue(tempDirPath.mkdir());

    // Create a testDir and file underneath directory
    int count = 5;
    List<String> expectedNonRecursive = new ArrayList<>();
    List<String> expectedRecursive = new ArrayList<>();
    for (int i = 0; i < count; i++) {
      File testDir = new File(tempDirPath, "testDir" + i);
      Assert.assertTrue(testDir.mkdir());
      expectedNonRecursive.add(testDir.getAbsolutePath());

      File testFile = new File(testDir, "testFile" + i);
      Assert.assertTrue(testFile.createNewFile());
      expectedRecursive.add(testDir.getAbsolutePath());
      expectedRecursive.add(testFile.getAbsolutePath());
    }
    File testDirEmpty = new File(tempDirPath, "testDirEmpty");
    Assert.assertTrue(testDirEmpty.mkdir());
    expectedNonRecursive.add(testDirEmpty.getAbsolutePath());
    expectedRecursive.add(testDirEmpty.getAbsolutePath());

    File testRootFile = new File(tempDirPath, "testRootFile");
    Assert.assertTrue(testRootFile.createNewFile());
    expectedNonRecursive.add(testRootFile.getAbsolutePath());
    expectedRecursive.add(testRootFile.getAbsolutePath());

    // Assert that recursive list files and nonrecursive list files are as expected
    String[] files = localPinotFS.listFiles(tempDirPath.toURI(), false);
    Assert.assertEquals(files.length, count + 2);
    Assert.assertTrue(expectedNonRecursive.containsAll(Arrays.asList(files)), Arrays.toString(files));
    files = localPinotFS.listFiles(tempDirPath.toURI(), true);
    Assert.assertEquals(files.length, count * 2 + 2);
    Assert.assertTrue(expectedRecursive.containsAll(Arrays.asList(files)), Arrays.toString(files));

    // Assert that recursive list files and nonrecursive list files with file info are as expected
    List<FileMetadata> fileMetadata = localPinotFS.listFilesWithMetadata(tempDirPath.toURI(), false);
    Assert.assertEquals(fileMetadata.size(), count + 2);
    Assert.assertEquals(fileMetadata.stream().filter(FileMetadata::isDirectory).count(), count + 1);
    Assert.assertEquals(fileMetadata.stream().filter(f -> !f.isDirectory()).count(), 1);
    Assert.assertTrue(expectedNonRecursive
            .containsAll(fileMetadata.stream().map(FileMetadata::getFilePath).collect(Collectors.toSet())),
        fileMetadata.toString());
    fileMetadata = localPinotFS.listFilesWithMetadata(tempDirPath.toURI(), true);
    Assert.assertEquals(fileMetadata.size(), count * 2 + 2);
    Assert.assertEquals(fileMetadata.stream().filter(FileMetadata::isDirectory).count(), count + 1);
    Assert.assertEquals(fileMetadata.stream().filter(f -> !f.isDirectory()).count(), count + 1);
    Assert.assertTrue(
        expectedRecursive.containsAll(fileMetadata.stream().map(FileMetadata::getFilePath).collect(Collectors.toSet())),
        fileMetadata.toString());
  }