public static long sizeOf(Path path) throws IOException {
    SizeVisitor visitor = new SizeVisitor();
    Files.walkFileTree(path, visitor);
    return visitor.size;
  }
@Test
  public void sizeOf_sums_sizes_of_all_files_in_directory() throws IOException {
    File dir = temporaryFolder.newFolder();
    File child = new File(dir, "child.txt");
    File grandChild1 = new File(dir, "grand/child1.txt");
    File grandChild2 = new File(dir, "grand/child2.txt");
    FileUtils.write(child, "foo", UTF_8);
    FileUtils.write(grandChild1, "bar", UTF_8);
    FileUtils.write(grandChild2, "baz", UTF_8);

    long childSize = FileUtils2.sizeOf(child.toPath());
    assertThat(childSize).isPositive();
    long grandChild1Size = FileUtils2.sizeOf(grandChild1.toPath());
    assertThat(grandChild1Size).isPositive();
    long grandChild2Size = FileUtils2.sizeOf(grandChild2.toPath());
    assertThat(grandChild2Size).isPositive();

    assertThat(FileUtils2.sizeOf(dir.toPath()))
      .isEqualTo(childSize + grandChild1Size + grandChild2Size);

    // sanity check by comparing commons-io
    assertThat(FileUtils2.sizeOf(dir.toPath()))
      .isEqualTo(FileUtils.sizeOfDirectory(dir));
  }