List of usage examples for java.nio.file Files walkFileTree
public static Path walkFileTree(Path start, FileVisitor<? super Path> visitor) throws IOException
From source file:net.doubledoordev.backend.server.Server.java
public void init() { if (this.logger != null) return; // don't do this twice. this.logger = LogManager.getLogger(ID); this.folder = new File(SERVERS, ID); this.backupFolder = new File(BACKUPS, ID); this.propertiesFile = new File(folder, SERVER_PROPERTIES); if (!backupFolder.exists()) backupFolder.mkdirs();/*ww w . j a va 2s . c o m*/ if (!folder.exists()) folder.mkdir(); try { SizeCounter sizeCounter = new SizeCounter(); Files.walkFileTree(getFolder().toPath(), sizeCounter); size[0] = sizeCounter.getSizeInMB(); sizeCounter = new SizeCounter(); if (getBackupFolder().exists()) Files.walkFileTree(getBackupFolder().toPath(), sizeCounter); size[1] = sizeCounter.getSizeInMB(); size[2] = size[0] + size[1]; } catch (IOException ignored) { } try { getProperties(); saveProperties(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.gitpitch.services.DiskService.java
public void copyDirectory(Path source, Path dest) { log.debug("copyDirectory: source={}, dest={}", source, dest); try {//from w w w .j av a 2 s.com Files.walkFileTree(source, new SimpleFileVisitor<Path>() { public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path relative = source.relativize(dir); Path visitPath = Paths.get(dest.toString(), relative.toString()); ensure(visitPath); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path copyTarget = Paths.get(dest.toString(), source.relativize(file).toString()); if (!file.getFileName().toString().matches("\\..*") && !copyTarget.getFileName().toString().matches("\\..*")) { Files.copy(file, copyTarget); } return FileVisitResult.CONTINUE; } }); } catch (Exception cex) { log.warn("copyDirectory: source={}, dest={}, ex={}", source, dest, cex); } }
From source file:org.fao.geonet.kernel.harvest.harvester.localfilesystem.LocalFilesystemHarvester.java
/** * Aligns new results from filesystem harvesting. Contrary to practice in e.g. CSW Harvesting, * files removed from the harvesting source are NOT removed from the database. Also, no checks * on modification date are done; the result gets inserted or replaced if the result appears to * be in a supported schema./* w ww . j a v a 2 s . co m*/ * * @param root the directory to visit */ private HarvestResult align(Path root) throws Exception { log.debug("Start of alignment for : " + params.getName()); final LocalFsHarvesterFileVisitor visitor = new LocalFsHarvesterFileVisitor(cancelMonitor, context, params, this, log); if (params.recurse) { Files.walkFileTree(root, visitor); } else { try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) { for (Path path : paths) { if (path != null && Files.isRegularFile(path)) { visitor.visitFile(path, Files.readAttributes(path, BasicFileAttributes.class)); } } } } result = visitor.getResult(); log.debug(String.format("Scan directory is done. %d files analyzed.", result.totalMetadata)); Set<Integer> idsForHarvestingResult = visitor.getListOfRecords(); Set<Integer> idsResultHs = Sets.newHashSet(idsForHarvestingResult); if (!params.nodelete) { log.debug("Starting to delete locally existing metadata " + "from the same source if they " + " were not in this harvesting result..."); List<Integer> existingMetadata = context.getBean(MetadataRepository.class) .findAllIdsBy(MetadataSpecs.hasHarvesterUuid(params.getUuid())); for (Integer existingId : existingMetadata) { if (cancelMonitor.get()) { return this.result; } if (!idsResultHs.contains(existingId)) { log.debug(" Removing: " + existingId); dataMan.deleteMetadata(context, existingId.toString()); result.locallyRemoved++; } } } log.debug("Starting indexing in batch thread pool..."); List<Integer> listOfRecordsToIndex = Lists.newArrayList(visitor.getListOfRecordsToIndex()); log.debug(String.format("Starting indexing in batch thread pool of %d updated records ...", listOfRecordsToIndex.size())); dataMan.batchIndexInThreadPool(context, listOfRecordsToIndex); log.debug("End of alignment for : " + params.getName()); return result; }
From source file:org.cryptomator.frontend.webdav.servlet.DavFolder.java
public void removeMemberInternal(DavNode member) throws DavException { try {/* www . j a v a 2s . c om*/ // The DELETE method on a collection must act as if a "Depth: infinity" header was used on it Files.walkFileTree(member.path, new DeletingFileVisitor()); } catch (NoSuchFileException e) { throw new DavException(DavServletResponse.SC_NOT_FOUND); } catch (IOException e) { throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e); } }
From source file:org.apache.tika.batch.fs.strawman.StrawManTikaAppDriver.java
@Override public Integer call() throws Exception { long start = new Date().getTime(); TikaVisitor v = new TikaVisitor(); Files.walkFileTree(inputRoot, v); int processed = v.getProcessed(); double elapsedSecs = ((double) new Date().getTime() - (double) start) / (double) 1000; LOG.info("Finished processing {} files in {} seconds.", processed, elapsedSecs); return processed; }
From source file:sadl.modellearner.rtiplus.SimplePDRTALearner.java
private Path initStepsDir(String dir) throws IOException { if (dir != null) { final Path p = Paths.get(dir, "steps"); if (Files.exists(directory) && Files.isDirectory(directory)) { Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override//from www . j a v a 2s. c o m public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path d, IOException e) throws IOException { if (e == null) { Files.delete(d); return FileVisitResult.CONTINUE; } else { throw e; } } }); } Files.createDirectories(directory); return p; } else { return null; } }
From source file:uk.co.unclealex.executable.impl.MakeLinksCommandRunnerTest.java
protected Path copy(String testCase, String directoryName) throws IOException { Path sourceDir = rootDir.resolve(testCase).resolve(directoryName); Path target = tmpDir.resolve(directoryName); Files.createDirectories(target); if (Files.exists(sourceDir)) { FileUtils.copyDirectory(sourceDir.toFile(), target.toFile()); FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() { @Override/* ww w .j av a 2 s . c o m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String name = file.getFileName().toString(); for (Entry<String, Path> entry : symlinksByName.entrySet()) { String suffix = entry.getKey(); Path symlink = entry.getValue(); if (name.endsWith(suffix)) { Files.delete(file); String newName = name.substring(0, name.length() - suffix.length()); Files.createSymbolicLink(file.resolveSibling(newName), symlink); return FileVisitResult.CONTINUE; } } return FileVisitResult.CONTINUE; } }; Files.walkFileTree(target, visitor); } return target; }
From source file:au.edu.uq.cmm.paul.servlet.WebUIController.java
private ArrayList<BuildInfo> loadBuildInfo(ServletContext servletContext) { final ArrayList<BuildInfo> res = new ArrayList<>(); res.add(BuildInfo.readBuildInfo("au.edu.uq.cmm", "aclslib")); res.add(BuildInfo.readBuildInfo("au.edu.uq.cmm", "eccles")); try {// w w w .j a va 2 s . c o m Path start = FileSystems.getDefault().getPath(servletContext.getRealPath("/META-INF/maven")); Files.walkFileTree(start, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().equals("pom.properties")) { try (InputStream is = new FileInputStream(file.toFile())) { res.add(BuildInfo.readBuildInfo(is)); } } return FileVisitResult.CONTINUE; } }); } catch (IOException ex) { LOG.error("Problem loading build info"); } return res; }
From source file:com.opentable.etcd.EtcdInstance.java
@Override public synchronized void close() { stop();/* ww w. j ava2 s. c o m*/ try { if (configuration.isDestroyNodeOnExit()) { Files.walkFileTree(configuration.getDataDirectory(), DeleteRecursively.INSTANCE); } } catch (IOException e) { LOGGER.warn("Failed to delete etcd data directoy", e); } }
From source file:org.cryptomator.webdav.jackrabbit.EncryptedDir.java
@Override public void removeMember(DavResource member) throws DavException { final Path memberPath = ResourcePathUtils.getPhysicalPath(member); try {/* w w w . ja va2 s . c o m*/ if (Files.exists(memberPath)) { Files.walkFileTree(memberPath, new DeletingFileVisitor()); } } catch (SecurityException e) { throw new DavException(DavServletResponse.SC_FORBIDDEN, e); } catch (IOException e) { throw new IORuntimeException(e); } }