HdfsUtils { public static long getDirectorySize(Path path, FileSystem fs, PathFilter filter) throws IOException { PathSizeVisitor visitor = new PathSizeVisitor(); PathFilter composite = new PathFilters.CompositePathFilter( PathFilters.newExcludeDirectoriesFilter(fs.getConf()), filter); walkPath(path, fs, composite, visitor); return visitor.getSize(); } private  HdfsUtils(); static void walkPath(Path path,
                              FileSystem fs,
                              PathFilter filter,
                              PathVisitor visitor); static void collectPaths(Path path,
                                  FileSystem fs,
                                  PathFilter filter,
                                  final List<Path> accumulator); static long getDirectorySize(Path path, FileSystem fs, PathFilter filter); static long getDirectorySize(Path path, FileSystem fs); static List<Path> expandGlobs(List<String> pathsWithGlobs, Configuration conf);  }
@Test public void testGetDirectorySize() throws Exception { Path p = new Path(SAMPLE_DIR_LOCATION + "sample_dir"); long size = HdfsUtils.getDirectorySize(p, p.getFileSystem(new Configuration())); assertEquals(18, size); }
@Test public void testGetDirectorySizeWithFilter() throws Exception { Path p = new Path(SAMPLE_DIR_LOCATION + "sample_dir"); long size = HdfsUtils.getDirectorySize( p, p.getFileSystem(new Configuration()), PathFilters.ACCEPT_ALL_PATHS_FILTER); assertEquals(18, size); size = HdfsUtils.getDirectorySize( p, p.getFileSystem(new Configuration()), SKIP_A_PATH_FILTER); assertEquals(16, size); }