List of usage examples for java.nio.file Files newDirectoryStream
public static DirectoryStream<Path> newDirectoryStream(Path dir, DirectoryStream.Filter<? super Path> filter) throws IOException
From source file:paketti.AbstractReader.java
protected static DirectoryStream<Path> getDirStream(Path rootDirPath) throws IOException { return Files.newDirectoryStream(rootDirPath, getDirsFilter()); }
From source file:org.libraryweasel.configmanager.JsonConfigManager.java
@Override public List<String> getConfigurations() { List<String> result = new ArrayList<>(); Path dir = pathsService.getInstancePath("config/"); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.{json}")) { for (Path entry : stream) { result.add(entry.getFileName().toString()); }/*from w ww. j av a2 s .co m*/ } catch (IOException ex) { throw new RuntimeException(ex); } return result; }
From source file:ch.digitalfondue.jfiveparse.TreeConstructionTest.java
@Parameters(name = "{0}:{index}:{2}") public static List<Object[]> data() throws IOException { List<Object[]> data = new ArrayList<>(); try (DirectoryStream<Path> ds = Files .newDirectoryStream(Paths.get("src/test/resources/html5lib-tests/tree-construction"), "*.dat")) { for (Path p : ds) { String file = new String(Files.readAllBytes(p), StandardCharsets.UTF_8); String[] testsAsString = file.split("\n\n#data\n"); for (String t : testsAsString) { TreeConstruction treeTest = parse(t); if (treeTest.scriptingFlag == null) { data.add(new Object[] { p.getFileName().toString(), treeTest, false }); data.add(new Object[] { p.getFileName().toString(), treeTest, true }); } else if (treeTest.scriptingFlag) { data.add(new Object[] { p.getFileName().toString(), treeTest, true }); } else { data.add(new Object[] { p.getFileName().toString(), treeTest, false }); }//from ww w .ja v a 2 s .c om } } } data.sort(new Comparator<Object[]>() { public int compare(Object[] o1, Object[] o2) { return new CompareToBuilder().append((String) o1[0], (String) o2[0]) .append((boolean) o1[2], (boolean) o2[2]).toComparison(); } }); return data; }
From source file:it.polimi.diceH2020.launcher.FileService.java
public Stream<Path> getBaseSolutionsPath() { String strDir = settings.getSolInstanceDir(); Path dir = FileSystems.getDefault().getPath(strDir); if (Files.notExists(dir)) { Path currentRelativePath = Paths.get(""); dir = FileSystems.getDefault() .getPath(currentRelativePath.toAbsolutePath().toString() + File.pathSeparator + strDir); }/* ww w . j ava 2 s.c o m*/ DirectoryStream<Path> stream; try { stream = Files.newDirectoryStream(dir, "*.{json}"); return StreamSupport.stream(stream.spliterator(), false); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.digitalpebble.storm.crawler.spout.FileSpout.java
public FileSpout(String dir, String filter, Scheme scheme) { Path pdir = Paths.get(dir); List<String> f = new LinkedList<String>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(pdir, filter)) { for (Path entry : stream) { String inputFile = entry.toAbsolutePath().toString(); f.add(inputFile);//w w w. ja v a 2s .c om LOG.info("Input : {}", inputFile); } } catch (IOException ioe) { LOG.error("IOException: %s%n", ioe); } _inputFiles = f.toArray(new String[f.size()]); _scheme = scheme; }
From source file:org.sonarsource.sonarlint.core.container.global.GlobalTempFolderProvider.java
private static void cleanTempFolders(Path path) throws IOException { if (Files.exists(path)) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, new CleanFilter())) { for (Path p : stream) { FileUtils.deleteQuietly(p.toFile()); }//w w w.j a v a 2s.c o m } } }
From source file:com.devti.JavaXMPPBot.JavaXMPPBot.java
@Override public void init(DaemonContext context) throws DaemonInitException, Exception { // Get paths//from ww w . j ava2s . c o m String[] args = context.getArguments(); Path configsDir, logsDir; if (args.length > 0) { configsDir = Paths.get(args[0]); } else { configsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "conf.d"); } if (args.length > 1) { logsDir = Paths.get(args[1]); } else { logsDir = Paths.get(System.getProperty("user.home"), "JavaXMPPBot", "log.d"); } if (!logsDir.toFile().exists()) { throw new DaemonInitException("Logs directory '" + logsDir + "' doesn't exist."); } // Get bot configs List<Path> botConfigs = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(configsDir, "*.conf")) { for (Path entry : stream) { botConfigs.add(entry); } } catch (DirectoryIteratorException e) { throw new DaemonInitException( "Can't list configs directory '" + configsDir + "': " + e.getLocalizedMessage()); } if (botConfigs.size() <= 0) { throw new DaemonInitException("There is no .conf files in '" + configsDir + "' directory."); } // Load bots for (Path config : botConfigs) { String id = config.getFileName().toString().replaceFirst(".conf$", ""); Path log = Paths.get(logsDir.toString(), id + ".log"); try { bots.add(new XMPPBot(id, config, new Log(log))); } catch (Exception e) { throw new DaemonInitException( "Can't load a bot with config file '" + config + "': " + e.getLocalizedMessage()); } } }
From source file:com.digitalpebble.stormcrawler.spout.FileSpout.java
public FileSpout(String dir, String filter, Scheme scheme) { Path pdir = Paths.get(dir); _inputFiles = new LinkedList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(pdir, filter)) { for (Path entry : stream) { String inputFile = entry.toAbsolutePath().toString(); _inputFiles.add(inputFile);/*from ww w. ja v a2 s . c o m*/ LOG.info("Input : {}", inputFile); } } catch (IOException ioe) { LOG.error("IOException: %s%n", ioe); } _scheme = scheme; }
From source file:org.bonitasoft.web.designer.repository.AbstractLoader.java
protected List<T> getAll(Path directory, String glob) throws IOException { List<T> objects = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory, glob)) { for (Path path : directoryStream) { String id = getComponentId(path); objects.add(get(directory, id)); }/*from w w w.j a v a 2 s . c om*/ } return objects; }
From source file:com.liferay.sync.engine.SyncSystemTest.java
@Parameters public static Collection<Object[]> testFilePaths() throws Exception { Collection<Object[]> testFilePaths = new LinkedList<Object[]>(); Path testsFilePath = getResourceFilePath("tests"); DirectoryStream<Path> directoryStream = Files.newDirectoryStream(testsFilePath, "*.json"); for (Path testFilePath : directoryStream) { testFilePaths.add(new Object[] { testFilePath }); }// w w w. jav a 2s .co m return testFilePaths; }