@Test(expected = RuntimeException.class) public void givenAPathToFile_whenCountFilesIsCalled_thenExceptionIsThrown() throws IOException { Path tempFile = Files.createTempFile(this.getClass().getSimpleName(), "tmp"); HdfsUtils.countFiles(new Configuration(), tempFile.toString(), mock(PathFilter.class)); }
public static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter) throws IOException { Path path = new Path(pathname); FileSystem fileSystem = FileSystem.get(hadoopConf); if (fileSystem.exists(path) && fileSystem.isDirectory(path)) { return fileSystem.listStatus(path, pathFilter).length; } throw new RuntimeException(String.format("Path does not exist or is not a directory: %s", pathname)); }
HdfsUtils { public static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter) throws IOException { Path path = new Path(pathname); FileSystem fileSystem = FileSystem.get(hadoopConf); if (fileSystem.exists(path) && fileSystem.isDirectory(path)) { return fileSystem.listStatus(path, pathFilter).length; } throw new RuntimeException(String.format("Path does not exist or is not a directory: %s", pathname)); } }
HdfsUtils { public static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter) throws IOException { Path path = new Path(pathname); FileSystem fileSystem = FileSystem.get(hadoopConf); if (fileSystem.exists(path) && fileSystem.isDirectory(path)) { return fileSystem.listStatus(path, pathFilter).length; } throw new RuntimeException(String.format("Path does not exist or is not a directory: %s", pathname)); } private  HdfsUtils(); }
HdfsUtils { public static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter) throws IOException { Path path = new Path(pathname); FileSystem fileSystem = FileSystem.get(hadoopConf); if (fileSystem.exists(path) && fileSystem.isDirectory(path)) { return fileSystem.listStatus(path, pathFilter).length; } throw new RuntimeException(String.format("Path does not exist or is not a directory: %s", pathname)); } private  HdfsUtils(); static void remove(Configuration hadoopConf, String pathname); static List<String> listDirs(Configuration hadoopConf, String pathname); static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter); }
HdfsUtils { public static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter) throws IOException { Path path = new Path(pathname); FileSystem fileSystem = FileSystem.get(hadoopConf); if (fileSystem.exists(path) && fileSystem.isDirectory(path)) { return fileSystem.listStatus(path, pathFilter).length; } throw new RuntimeException(String.format("Path does not exist or is not a directory: %s", pathname)); } private  HdfsUtils(); static void remove(Configuration hadoopConf, String pathname); static List<String> listDirs(Configuration hadoopConf, String pathname); static int countFiles(Configuration hadoopConf, String pathname, PathFilter pathFilter);  }