List of usage examples for java.nio.file FileVisitResult CONTINUE
FileVisitResult CONTINUE
To view the source code for java.nio.file FileVisitResult CONTINUE.
Click Source Link
From source file:io.anserini.index.IndexWebCollection.java
static Deque<Path> discoverWarcFiles(Path p, final String suffix) { final Deque<Path> stack = new ArrayDeque<>(); FileVisitor<Path> fv = new SimpleFileVisitor<Path>() { @Override//from ww w . j a v a2 s . c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path name = file.getFileName(); if (name != null && name.toString().endsWith(suffix)) stack.add(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { if ("OtherData".equals(dir.getFileName().toString())) { LOG.info("Skipping: " + dir); return FileVisitResult.SKIP_SUBTREE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException ioe) { LOG.error("Visiting failed for " + file.toString(), ioe); return FileVisitResult.SKIP_SUBTREE; } }; try { Files.walkFileTree(p, fv); } catch (IOException e) { LOG.error("IOException during file visiting", e); } return stack; }
From source file:org.commonjava.test.compile.CompilerFixture.java
public List<File> scan(final File directory, final String pattern) throws IOException { final PathMatcher matcher = FileSystems.getDefault() .getPathMatcher("glob:" + directory.getCanonicalPath() + "/" + pattern); final List<File> sources = new ArrayList<>(); Files.walkFileTree(directory.toPath(), new SimpleFileVisitor<Path>() { @Override//from ww w. j a va2 s .c o m public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (matcher.matches(file)) { sources.add(file.toFile()); } return FileVisitResult.CONTINUE; } }); return sources; }
From source file:org.craftercms.studio.impl.v1.repository.disk.DiskContentRepository.java
/** * get immediate children for path/*from ww w .j a v a 2s . c o m*/ * @param path path to content */ public RepositoryItem[] getContentChildren(String path) { final List<RepositoryItem> retItems = new ArrayList<RepositoryItem>(); try { EnumSet<FileVisitOption> opts = EnumSet.of(FileVisitOption.FOLLOW_LINKS); final String finalPath = path; Files.walkFileTree(constructRepoPath(finalPath), opts, 1, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path visitPath, BasicFileAttributes attrs) throws IOException { if (!visitPath.equals(constructRepoPath(finalPath))) { RepositoryItem item = new RepositoryItem(); item.name = visitPath.toFile().getName(); String visitFolderPath = visitPath.toString();//.replace("/index.xml", ""); //Path visitFolder = constructRepoPath(visitFolderPath); item.isFolder = visitPath.toFile().isDirectory(); int lastIdx = visitFolderPath.lastIndexOf(File.separator + item.name); if (lastIdx > 0) { item.path = visitFolderPath.substring(0, lastIdx); } //item.path = visitFolderPath.replace("/" + item.name, ""); item.path = item.path.replace(getRootPath().replace("/", File.separator), ""); item.path = item.path.replace(File.separator + ".xml", ""); item.path = item.path.replace(File.separator, "/"); if (!".DS_Store".equals(item.name)) { logger.debug("ITEM NAME: {0}", item.name); logger.debug("ITEM PATH: {0}", item.path); logger.debug("ITEM FOLDER: ({0}): {1}", visitFolderPath, item.isFolder); retItems.add(item); } } return FileVisitResult.CONTINUE; } }); } catch (Exception err) { // log this error } RepositoryItem[] items = new RepositoryItem[retItems.size()]; items = retItems.toArray(items); return items; }
From source file:de.alexkamp.sandbox.ChrootSandbox.java
@Override public void walkDirectoryTree(String basePath, final DirectoryWalker walker) throws IOException { final int baseNameCount = data.getBaseDir().toPath().getNameCount(); File base = new File(data.getBaseDir(), basePath); Files.walkFileTree(base.toPath(), new FileVisitor<Path>() { @Override/*from www. j av a2 s .c o m*/ public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes basicFileAttributes) throws IOException { if (walker.visitDirectory(calcSubpath(path))) { return FileVisitResult.CONTINUE; } return FileVisitResult.SKIP_SUBTREE; } private String calcSubpath(Path path) { if (path.getNameCount() == baseNameCount) { return "/"; } return "/" + path.subpath(baseNameCount, path.getNameCount()).toString(); } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { String subpath = calcSubpath(path); if (walker.visitFile(subpath)) { try (InputStream is = Files.newInputStream(path)) { walker.visitFileContent(subpath, is); } } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException e) throws IOException { if (walker.failed(e)) { return FileVisitResult.CONTINUE; } else { return FileVisitResult.TERMINATE; } } @Override public FileVisitResult postVisitDirectory(Path path, IOException e) throws IOException { return FileVisitResult.CONTINUE; } }); }
From source file:org.elasticsearch.plugins.PluginManagerIT.java
/** creates a plugin .zip and bad checksum file and returns the url for testing */ private String createPluginWithBadChecksum(final Path structure, String... properties) throws IOException { writeProperties(structure, properties); Path zip = createTempDir().resolve(structure.getFileName() + ".zip"); try (ZipOutputStream stream = new ZipOutputStream(Files.newOutputStream(zip))) { Files.walkFileTree(structure, new SimpleFileVisitor<Path>() { @Override/* www.j a v a 2 s. c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { stream.putNextEntry(new ZipEntry(structure.relativize(file).toString())); Files.copy(file, stream); return FileVisitResult.CONTINUE; } }); } if (randomBoolean()) { writeSha1(zip, true); } else { writeMd5(zip, true); } return zip.toUri().toURL().toString(); }
From source file:org.apache.tika.batch.fs.FSBatchTestBase.java
public static void deleteDirectory(Path dir) throws IOException { Files.walkFileTree(dir, new SimpleFileVisitor<Path>() { @Override// w ww. j a v a 2 s .c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); }
From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java
License:asdf
@AfterClass public static void testdownClass() throws IOException { Files.walkFileTree(tempFolder, new SimpleFileVisitor<Path>() { @Override/* w w w .jav a2 s.c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); }
From source file:de.prozesskraft.pkraft.Waitinstance.java
/** * ermittelt alle process binaries innerhalb eines directory baumes * @param pathScandir//from w w w .j a v a 2 s . co m * @return */ private static String[] getProcessBinaries(String pathScandir) { final ArrayList<String> allProcessBinaries = new ArrayList<String>(); // den directory-baum durchgehen und fuer jeden eintrag ein entity erstellen try { Files.walkFileTree(Paths.get(pathScandir), new FileVisitor<Path>() { // called after a directory visit is complete public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } // called before a directory visit public FileVisitResult preVisitDirectory(Path walkingDir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } // called for each file visited. the basic file attributes of the file are also available public FileVisitResult visitFile(Path walkingFile, BasicFileAttributes attrs) throws IOException { // ist es ein process.pmb file? if (walkingFile.endsWith("process.pmb")) { allProcessBinaries.add(new java.io.File(walkingFile.toString()).getAbsolutePath()); } return FileVisitResult.CONTINUE; } // called for each file if the visit failed public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return allProcessBinaries.toArray(new String[allProcessBinaries.size()]); }
From source file:org.fao.geonet.api.mapservers.GeoFile.java
/** * Returns the names of the raster layers (GeoTIFFs) in the geographic file. * * @return a collection of layer names//ww w. j a v a 2s .com */ public Collection<String> getRasterLayers() throws IOException { final LinkedList<String> layers = new LinkedList<String>(); if (zipFile != null) { for (Path path : zipFile.getRootDirectories()) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fileName = file.getFileName().toString(); if (fileIsGeotif(fileName)) { layers.add(getBase(fileName)); } return FileVisitResult.CONTINUE; } }); } } else { String fileName = file.getFileName().toString(); if (fileIsGeotif(fileName)) { layers.add(getBase(fileName)); } } return layers; }
From source file:ch.bender.evacuate.Runner.java
/** * preVisitDirectory// w w w . j a va2 s . c o m * <p> * @param aDir * @param aAttrs * @return * @throws IOException */ FileVisitResult preVisitDirectory(Path aDir, BasicFileAttributes aAttrs) throws IOException { if (aDir.equals(myBackupDir)) { myLog.debug("Visiting the backup root. This directory is never subject of evactuation"); return FileVisitResult.CONTINUE; } myLog.debug("Visiting directory " + aDir.toString()); return visit(aDir); }