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:org.apache.solr.handler.TestReplicationHandlerBackup.java
@Test public void testBackupOnCommit() throws Exception { //Index/*from www.j av a 2s . co m*/ int nDocs = BackupRestoreUtils.indexDocs(masterClient, DEFAULT_TEST_COLLECTION_NAME, docsSeed); //Confirm if completed CheckBackupStatus checkBackupStatus = new CheckBackupStatus((HttpSolrClient) masterClient, DEFAULT_TEST_CORENAME); while (!checkBackupStatus.success) { checkBackupStatus.fetchStatus(); Thread.sleep(1000); } //Validate try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) { Path snapDir = stream.iterator().next(); verify(snapDir, nDocs); } }
From source file:com.acmutv.ontoqa.tool.io.IOManager.java
/** * Returns the list of all files inside {@code directory}. * @param directory the directory to inspect. * @param matcher the file pattern matching. * @return the list of all files inside {@code directory}. * @throws IOException when files cannot be listed in {@code directory}. *///from ww w. j a v a2s . co m public static List<Path> allFiles(String directory, String matcher) throws IOException { List<Path> files = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(directory), matcher)) { directoryStream.forEach(f -> { if (Files.isRegularFile(f)) files.add(f); }); } return files; }
From source file:ee.ria.xroad.common.conf.globalconf.ConfigurationDirectory.java
/** * Reloads the configuration directory. Only files that are new or have * changed, are actually loaded./*from w w w. j a v a 2 s . c o m*/ * @throws Exception if an error occurs during reload */ public synchronized void reload() throws Exception { Map<String, PrivateParameters> privateParams = new HashMap<>(); Map<String, SharedParameters> sharedParams = new HashMap<>(); log.trace("Reloading configuration from {}", path); instanceIdentifier = null; try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, Files::isDirectory)) { for (Path instanceDir : stream) { log.trace("Loading parameters from {}", instanceDir); loadPrivateParameters(instanceDir, privateParams); loadSharedParameters(instanceDir, sharedParams); } } this.privateParameters = privateParams; this.sharedParameters = sharedParams; }
From source file:at.ac.tuwien.infosys.repository.LocalComponentRepository.java
protected Path findFolder(Path searchPath, String searchName) { Path foundPath = null;/*from ww w . j a v a 2 s . co m*/ try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(searchPath, searchName)) { for (Path path : directoryStream) { foundPath = path; break; } } catch (IOException ex) { ex.printStackTrace(); } return foundPath; }
From source file:im.bci.gamesitekit.GameSiteKitMain.java
private void copyScreenshots() throws IOException { Files.createDirectories(screenshotsOutputDir); try (DirectoryStream<Path> stream = Files.newDirectoryStream(screenshotsInputDir, IMAGE_GLOB)) { for (Path image : stream) { Files.copy(image, screenshotsOutputDir.resolve(screenshotsInputDir.relativize(image))); }//from www .j ava 2 s. co m } Files.createDirectories(screenshotThumbnailsOutputDir); try (DirectoryStream<Path> stream = Files.newDirectoryStream(screenshotThumbnailsInputDir, IMAGE_GLOB)) { for (Path image : stream) { Files.copy(image, screenshotThumbnailsOutputDir.resolve(screenshotThumbnailsInputDir.relativize(image))); } } }
From source file:org.wikidata.wdtk.util.DirectoryManagerImpl.java
@Override public List<String> getSubdirectories(String glob) throws IOException { List<String> result = new ArrayList<String>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(this.directory, glob)) { for (Path entry : directoryStream) { if (Files.isDirectory(entry)) { result.add(entry.getFileName().toString()); }// www. j a v a2 s . c o m } } return result; }
From source file:de.appsolve.padelcampus.utils.HtmlResourceUtil.java
private String concatenateCss(ServletContext context, Path path, Path outFile) throws FileNotFoundException, IOException { DirectoryStream<Path> cssFiles = Files.newDirectoryStream(path, "*.css"); if (Files.exists(outFile)) { Files.delete(outFile);/* w ww . j a va 2 s . co m*/ } List<Path> sortedFiles = new ArrayList<>(); for (Path cssFile : cssFiles) { sortedFiles.add(cssFile); } Collections.sort(sortedFiles, new PathByFileNameComparator()); for (Path cssFile : sortedFiles) { Files.write(outFile, Files.readAllBytes(cssFile), StandardOpenOption.CREATE, StandardOpenOption.APPEND); } byte[] cssData; if (Files.exists(outFile)) { cssData = Files.readAllBytes(outFile); } else { //read from classpath InputStream is = context.getResourceAsStream(ALL_MIN_CSS); cssData = IOUtils.toByteArray(is); } String css = new String(cssData, Constants.UTF8); return css; }
From source file:org.opencb.cellbase.app.cli.VariantAnnotationCommandExecutor.java
private void runBenchmark() { try {//w w w . ja v a 2 s .c om FastaIndexManager fastaIndexManager = getFastaIndexManger(); DirectoryStream<Path> stream = Files.newDirectoryStream(input, entry -> { return entry.getFileName().toString().endsWith(".vep"); }); DataWriter dataWriter = getDataWriter(output.toString()); ParallelTaskRunner.Config config = new ParallelTaskRunner.Config(numThreads, batchSize, QUEUE_CAPACITY, false); List<ParallelTaskRunner.TaskWithException<VariantAnnotation, Pair<VariantAnnotationDiff, VariantAnnotationDiff>, Exception>> variantAnnotatorTaskList = getBenchmarkTaskList( fastaIndexManager); for (Path entry : stream) { logger.info("Processing file '{}'", entry.toString()); DataReader dataReader = new VepFormatReader(input.resolve(entry.getFileName()).toString()); ParallelTaskRunner<VariantAnnotation, Pair<VariantAnnotationDiff, VariantAnnotationDiff>> runner = new ParallelTaskRunner<>( dataReader, variantAnnotatorTaskList, dataWriter, config); runner.run(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.kitodo.serviceloader.KitodoServiceLoader.java
/** * If the found jar files have frontend files, they will be extracted and * copied into the frontend folder of the core module. Before copying, * existing frontend files of the same module will be deleted from the core * module. Afterwards the created temporary folder will be deleted as well. */// w w w. ja va2 s . co m private void loadFrontendFilesIntoCore() { Path moduleFolder = FileSystems.getDefault().getPath(modulePath); try (DirectoryStream<Path> stream = Files.newDirectoryStream(moduleFolder, JAR)) { for (Path f : stream) { File loc = new File(f.toString()); try (JarFile jarFile = new JarFile(loc)) { if (hasFrontendFiles(jarFile)) { Path temporaryFolder = Files.createTempDirectory(SYSTEM_TEMP_FOLDER, TEMP_DIR_PREFIX); File tempDir = new File(Paths.get(temporaryFolder.toUri()).toAbsolutePath().toString()); extractFrontEndFiles(loc.getAbsolutePath(), tempDir); String moduleName = extractModuleName(tempDir); if (!moduleName.isEmpty()) { FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(false); String filePath = session.getServletContext().getRealPath(File.separator + PAGES_FOLDER) + File.separator + moduleName; FileUtils.deleteDirectory(new File(filePath)); String resourceFolder = String.join(File.separator, Arrays.asList(tempDir.getAbsolutePath(), META_INF_FOLDER, RESOURCES_FOLDER)); copyFrontEndFiles(resourceFolder, filePath); } else { logger.info("No module found in JarFile '" + jarFile.getName() + "'."); } FileUtils.deleteDirectory(tempDir); } } } } catch (Exception e) { logger.error(ERROR, e.getMessage()); } }
From source file:org.apache.solr.handler.TestReplicationHandlerBackup.java
@Test public void doTestBackup() throws Exception { int nDocs = BackupRestoreUtils.indexDocs(masterClient, DEFAULT_TEST_COLLECTION_NAME, docsSeed); //Confirm if completed CheckBackupStatus checkBackupStatus = new CheckBackupStatus((HttpSolrClient) masterClient, DEFAULT_TEST_CORENAME);//from w w w. j a va2 s. c om while (!checkBackupStatus.success) { checkBackupStatus.fetchStatus(); Thread.sleep(1000); } Path[] snapDir = new Path[5]; //One extra for the backup on commit //First snapshot location try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) { snapDir[0] = stream.iterator().next(); } boolean namedBackup = random().nextBoolean(); String firstBackupTimestamp = null; String[] backupNames = null; if (namedBackup) { backupNames = new String[4]; } for (int i = 0; i < 4; i++) { final String backupName = TestUtil.randomSimpleString(random(), 1, 20); if (!namedBackup) { if (addNumberToKeepInRequest) { runBackupCommand(masterJetty, ReplicationHandler.CMD_BACKUP, "&" + backupKeepParamName + "=2"); } else { runBackupCommand(masterJetty, ReplicationHandler.CMD_BACKUP, ""); } } else { runBackupCommand(masterJetty, ReplicationHandler.CMD_BACKUP, "&name=" + backupName); backupNames[i] = backupName; } checkBackupStatus = new CheckBackupStatus((HttpSolrClient) masterClient, DEFAULT_TEST_CORENAME, firstBackupTimestamp); while (!checkBackupStatus.success) { checkBackupStatus.fetchStatus(); Thread.sleep(1000); } if (i == 0) { firstBackupTimestamp = checkBackupStatus.backupTimestamp; } if (!namedBackup) { try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) { snapDir[i + 1] = stream.iterator().next(); } } else { try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot." + backupName)) { snapDir[i + 1] = stream.iterator().next(); } } verify(snapDir[i + 1], nDocs); } //Test Deletion of named backup if (namedBackup) { testDeleteNamedBackup(backupNames); } else { //5 backups got created. 4 explicitly and one because a commit was called. // Only the last two should still exist. int count = 0; try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(master.getDataDir()), "snapshot*")) { Iterator<Path> iter = stream.iterator(); while (iter.hasNext()) { iter.next(); count++; } } //There will be 2 backups, otherwise 1 if (backupKeepParamName.equals(ReplicationHandler.NUMBER_BACKUPS_TO_KEEP_REQUEST_PARAM)) { assertEquals(2, count); if (Files.exists(snapDir[0]) || Files.exists(snapDir[1]) || Files.exists(snapDir[2])) { fail("Backup should have been cleaned up because " + backupKeepParamName + " was set to 2."); } } else { assertEquals(1, count); if (Files.exists(snapDir[0]) || Files.exists(snapDir[1]) || Files.exists(snapDir[2]) || Files.exists(snapDir[3])) { fail("Backup should have been cleaned up because " + backupKeepParamName + " was set to 1."); } } } }