List of usage examples for java.nio.file Files newDirectoryStream
public static DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException
From source file:org.sonar.plugins.spcaf.SpcafSensor.java
private void addTree(Path file, Collection<Path> all) { try (DirectoryStream<Path> ds = Files.newDirectoryStream(file)) { for (Path child : ds) { if (folderExclusions.contains(file.getFileName().toString())) { continue; }/*from www . j a v a2 s . co m*/ all.add(child); if (Files.isDirectory(child)) { addTree(child, all); } } } catch (IOException ex) { LOG.info("SPCAF: IO Exception occured while attempted to read file: " + ex.getMessage()); } }
From source file:org.apache.storm.daemon.supervisor.AdvancedFSOps.java
public DirectoryStream<Path> newDirectoryStream(Path dir) throws IOException { return Files.newDirectoryStream(dir); }
From source file:org.openecomp.sdnc.uebclient.SdncUebCallback.java
public void deployDownloadedFiles(File incomingDir, File archiveDir, INotificationData data) { if (incomingDir == null) { incomingDir = new File(config.getIncomingDir()); if (!incomingDir.exists()) { incomingDir.mkdirs();/*from ww w.ja va 2 s . c om*/ } } if (archiveDir == null) { archiveDir = new File(config.getArchiveDir()); if (!archiveDir.exists()) { archiveDir.mkdirs(); } } String curFileName = ""; try (DirectoryStream<Path> stream = Files.newDirectoryStream(incomingDir.toPath())) { for (Path file : stream) { curFileName = file.toString(); handleSuccessfulDownload(null, null, null, null, file.toFile(), archiveDir); } } catch (Exception x) { // IOException can never be thrown by the iteration. // In this snippet, it can only be thrown by newDirectoryStream. LOG.warn("Cannot process spool file " + curFileName, x); } // Deploy scheduled deployments int numPasses = config.getMaxPasses(); deployList = new LinkedList[numPasses]; for (int i = 0; i < numPasses; i++) { deployList[i] = new LinkedList<DeployableArtifact>(); } for (int pass = 0; pass < config.getMaxPasses(); pass++) { if (deployList[pass] != null) { while (!deployList[pass].isEmpty()) { DeployableArtifact artifact = deployList[pass].pop(); DistributionStatusEnum deployResult = DistributionStatusEnum.DEPLOY_ERROR; try { deployResult = deploySpoolFile(artifact); } catch (Exception e) { LOG.error("Caught exception trying to deploy file", e); } IArtifactInfo artifactInfo = artifact.getArtifactInfo(); if ((artifactInfo != null) && (data != null)) { IDistributionClientResult deploymentStatus; deploymentStatus = client .sendDeploymentStatus(buildStatusMessage(client, data, artifactInfo, deployResult)); } } } } }
From source file:company.gonapps.loghut.dao.PostDao.java
public List<String> getYears() throws IOException { List<String> years = new LinkedList<>(); rrwl.readLock().lock();//w w w . j a va 2s .c o m try (DirectoryStream<Path> ds = Files .newDirectoryStream(Paths.get(settingDao.getSetting("posts.directory")))) { for (Path path : ds) { Matcher matcher = postYearPattern.matcher(path.toString()); if (matcher.find() && Files.isDirectory(path)) years.add(matcher.group(1)); } } finally { rrwl.readLock().unlock(); } Collections.sort(years, new YearComparator()); return years; }
From source file:org.bigbluebutton.api.RecordingService.java
private static List<File> getDirectories(String path) { List<File> files = new ArrayList<File>(); try {/*from w w w .java 2 s . c o m*/ DirectoryStream<Path> stream = Files.newDirectoryStream(FileSystems.getDefault().getPath(path)); Iterator<Path> iter = stream.iterator(); while (iter.hasNext()) { Path next = iter.next(); files.add(next.toFile()); } stream.close(); } catch (IOException e) { e.printStackTrace(); } return files; }
From source file:company.gonapps.loghut.dao.PostDao.java
public List<String> getMonths(int year) throws IOException { List<String> months = new LinkedList<>(); rrwl.readLock().lock();//ww w . ja v a 2s . c om try (DirectoryStream<Path> ds = Files.newDirectoryStream( Paths.get(settingDao.getSetting("posts.directory") + "/" + String.format("%04d", year)))) { for (Path path : ds) { Matcher matcher = postMonthPattern.matcher(path.toString()); if (matcher.find() && Files.isDirectory(path)) months.add(matcher.group(1)); } } rrwl.readLock().unlock(); Collections.sort(months, new MonthComparator()); return months; }
From source file:org.carcv.impl.core.io.FFMPEGVideoHandlerIT.java
@Test public void testCreateVideoInternal() throws IOException, InterruptedException { FFMPEGVideoHandler.copyCarImagesToDir(entry.getCarImages(), videoDir); DirectoryStream<Path> testpaths = Files.newDirectoryStream(videoDir); int counterTest = 0; for (Path p : testpaths) { assertTrue(Files.exists(p)); counterTest++;/*w w w .j a va2 s .c o m*/ } assertEquals(2, counterTest); DirectoryStream<Path> paths = Files.newDirectoryStream(videoDir); String imageSuffix = ".invalid"; for (Path p : paths) { imageSuffix = FFMPEGVideoHandler.getSuffix(p); if (imageSuffix != null) break; } Path output = Paths.get("/tmp", "video-" + new Random().nextInt() + "-" + System.currentTimeMillis() + "." + "mjpeg"); String command = "ffmpeg -y -f image2 -pattern_type glob -i \"" + videoDir.toAbsolutePath().toString() + File.separator + "*." + imageSuffix + "\" -r " + 2 + " " + output.toAbsolutePath().toString(); LOGGER.info("Executing: " + command); Process p = Runtime.getRuntime().exec(command); LOGGER.debug(getErrorMessage(p.getErrorStream())); LOGGER.debug("Return value: {}", p.waitFor()); assertTrue(Files.exists(output)); LOGGER.debug("Path of created video: {}", output); }
From source file:de.huberlin.wbi.cuneiform.core.cre.LocalThread.java
public static void deleteIfExists(Path f) throws IOException { if (!Files.exists(f, LinkOption.NOFOLLOW_LINKS)) return;//from www. ja v a 2 s .c om if (Files.isDirectory(f)) try (DirectoryStream<Path> stream = Files.newDirectoryStream(f)) { for (Path p : stream) deleteIfExists(p); } Files.delete(f); }
From source file:com.lukakama.serviio.watchservice.watcher.WatcherRunnable.java
private boolean isPathFullyAccessible(Path path) { if (!Files.exists(path)) { return false; }/* w w w. ja v a2 s .com*/ if (Files.isDirectory(path)) { DirectoryStream<Path> directoryStream = null; try { directoryStream = Files.newDirectoryStream(path); return true; } catch (IOException e) { log.debug("Unaccessible directory: {}", path, e); return false; } finally { IOUtils.closeQuietly(directoryStream); } } else { FileChannel fileChannel = null; try { fileChannel = FileChannel.open(path, StandardOpenOption.READ); fileChannel.position(Files.size(path)); return true; } catch (IOException e) { log.debug("Unaccessible file: {}", path, e); return false; } finally { IOUtils.closeQuietly(fileChannel); } } }
From source file:org.apache.taverna.robundle.TestBundles.java
protected boolean isEmpty(Path path) throws IOException { try (DirectoryStream<Path> ds = Files.newDirectoryStream(path)) { return !ds.iterator().hasNext(); }//from www. j ava 2 s. com }