Main { static List<File> locateFiles(String payloadFileSpec) { List<File> files = new ArrayList<>(); if ("-".equals(payloadFileSpec)) { try (Reader reader = new InputStreamReader(System.in); BufferedReader bufferedReader = new BufferedReader(reader)) { files = bufferedReader.lines() .map(File::new) .collect(Collectors.toList()); } catch (IOException e) { log.warn(e.getMessage(), e); } } else { File fileSpec = new File(payloadFileSpec); if (!fileSpec.exists()) { log.warn(String.format("'%s' does not exists.", fileSpec.getAbsolutePath())); } else if (fileSpec.isDirectory()) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(payloadFileSpec), "*.{XML,xml}")) { for (Path path : stream) { files.add(path.toFile()); } } catch (IOException e) { throw new IllegalStateException( String.format("Unable to list files %s; %s", payloadFileSpec, e.getMessage()), e); } } else if (fileSpec.isFile()) { files.add(fileSpec); } else { log.warn(String.format("'%s' is neither file nor directory.", fileSpec.getAbsoluteFile())); } } return files; }  static void main(String[] args);  }
@Test public void testLocateFiles() throws Exception { List<File> files = Main.locateFiles(tempDirectory.toString()); assertEquals(files.size(), 2); files = Main.locateFiles(tempFile.toString()); assertEquals(1, files.size()); }
@Test public void testStdin() throws Exception { InputStream saved = System.in; System.setIn( new FileInputStream(fileHoldingFileNames.toFile()) ); List<File> files = Main.locateFiles("-"); assertEquals(2, files.size()); System.setIn(saved); }