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:services.ImportExportService.java
public static List<DatabaseImage> findImportables(Path path) { final List<DatabaseImage> importable = new LinkedList<DatabaseImage>(); try {// w ww .j a va2s.com Files.walkFileTree(path, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (PathService.isImage(path)) { DatabaseImage image = DatabaseImage.forPath(path); if (hasFileToImport(image) && !image.imported) { importable.add(image); } } return FileVisitResult.CONTINUE; } }); } catch (IOException io) { io.printStackTrace(); return importable; } return importable; }
From source file:org.structr.web.maintenance.deploy.ComponentImportVisitor.java
@Override public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; }
From source file:org.apdplat.superword.tools.JavaCodeAnalyzer.java
public static Map<String, AtomicInteger> parseZip(String zipFile) { LOGGER.info("?ZIP" + zipFile); Map<String, AtomicInteger> data = new HashMap<>(); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), JavaCodeAnalyzer.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w . ja v a2 s . c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/java-source-code.txt"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); Map<String, AtomicInteger> r = parseFile(temp.toFile().getAbsolutePath()); r.keySet().forEach(k -> { data.putIfAbsent(k, new AtomicInteger()); data.get(k).addAndGet(r.get(k).get()); }); r.clear(); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?ZIP", e); } return data; }
From source file:org.apdplat.superword.extract.PhraseExtractor.java
public static Set<String> parseZip(String zipFile) { Set<String> data = new HashSet<>(); LOGGER.info("?ZIP" + zipFile); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), PhraseExtractor.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from www. j a v a 2 s . com*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/origin-html-temp.txt"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); data.addAll(parseFile(temp.toFile().getAbsolutePath())); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } return data; }
From source file:net.minecrell.quartz.launch.mappings.MappingsLoader.java
public static Mappings load(Logger logger) throws IOException { URI source;// w w w . jav a2s. c om try { source = requireNonNull(Mapping.class.getProtectionDomain().getCodeSource(), "Unable to find class source").getLocation().toURI(); } catch (URISyntaxException e) { throw new IOException("Failed to find class source", e); } Path location = Paths.get(source); logger.debug("Mappings location: {}", location); List<ClassNode> mappingClasses = new ArrayList<>(); // Load the classes from the source if (Files.isDirectory(location)) { // We're probably in development environment or something similar // Search for the class files Files.walkFileTree(location.resolve(PACKAGE), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (file.getFileName().toString().endsWith(".class")) { try (InputStream in = Files.newInputStream(file)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } return FileVisitResult.CONTINUE; } }); } else { // Go through the JAR file try (ZipFile zip = new ZipFile(location.toFile())) { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = StringUtils.removeStart(entry.getName(), MAPPINGS_DIR); if (entry.isDirectory() || !name.endsWith(".class") || !name.startsWith(PACKAGE_PREFIX)) { continue; } // Ok, we found something try (InputStream in = zip.getInputStream(entry)) { ClassNode classNode = MappingsParser.loadClassStructure(in); mappingClasses.add(classNode); } } } } return new Mappings(mappingClasses); }
From source file:org.jetbrains.webdemo.backend.executor.ExecutorUtils.java
public static ExecutionResult executeCompiledFiles(Map<String, byte[]> files, String mainClass, List<Path> kotlinRuntimeJars, String arguments, Path executorsPolicy, boolean isJunit) throws Exception { Path codeDirectory = null;/* w w w.ja va 2 s . com*/ try { codeDirectory = storeFilesInTemporaryDirectory(files); JavaExecutorBuilder executorBuilder = new JavaExecutorBuilder().enableAssertions().setMemoryLimit(32) .enableSecurityManager().setPolicyFile(executorsPolicy).addToClasspath(kotlinRuntimeJars) .addToClasspath(jarFiles).addToClasspath(codeDirectory); if (isJunit) { executorBuilder.addToClasspath(junit); executorBuilder.addToClasspath(hamcrest); executorBuilder.setMainClass("org.jetbrains.webdemo.executors.JunitExecutor"); executorBuilder.addArgument(codeDirectory.toString()); } else { executorBuilder.setMainClass("org.jetbrains.webdemo.executors.JavaExecutor"); executorBuilder.addArgument(mainClass); } for (String argument : arguments.split(" ")) { if (argument.trim().isEmpty()) continue; executorBuilder.addArgument(argument); } ProgramOutput output = executorBuilder.build().execute(); return parseOutput(output.getStandardOutput(), isJunit); } finally { try { if (codeDirectory != null) { Files.walkFileTree(codeDirectory, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.TERMINATE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } }); } } catch (IOException e) { ErrorWriter.getInstance().writeExceptionToExceptionAnalyzer(e, "Can't delete code directory"); } } }
From source file:com.ilscipio.scipio.common.FileListener.java
/** * Start a file listener (WatchService) and run a service of a given name and writes the result to the database * Can be used to implements EECAs to auto-update information based on file changes **//* w w w .j a v a 2 s .c om*/ public static void startFileListener(String name, String location) { try { if (UtilValidate.isNotEmpty(name) && UtilValidate.isNotEmpty(location)) { if (getThreadByName(name) != null) { Debug.logInfo("Filelistener " + name + " already started. Skipping...", module); } else { URL resLocation = UtilURL.fromResource(location); Path folderLocation = Paths.get(resLocation.toURI()); if (folderLocation == null) { throw new UnsupportedOperationException("Directory not found"); } final WatchService folderWatcher = folderLocation.getFileSystem().newWatchService(); // register all subfolders Files.walkFileTree(folderLocation, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { dir.register(folderWatcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY); return FileVisitResult.CONTINUE; } }); // start the file watcher thread below ScipioWatchQueueReader fileListener = new ScipioWatchQueueReader(folderWatcher, name, location); ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor( FILE_LISTENER_THREAD_GROUP, "filelistener-startup", Runtime.getRuntime().availableProcessors(), 0, true); try { executor.submit(fileListener, name); } finally { executor.shutdown(); } Debug.logInfo("Starting FileListener thread for " + name, module); } } } catch (Exception e) { Debug.logError("Could not start FileListener " + name + " for " + location + "\n" + e, module); } }
From source file:org.apdplat.superword.extract.DefinitionExtractor.java
public static Set<Word> parseZip(String zipFile) { Set<Word> data = new HashSet<>(); LOGGER.info("?ZIP" + zipFile); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), WordClassifier.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w . j av a 2s.co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/origin-html-temp.txt"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); data.addAll(parseFile(temp.toFile().getAbsolutePath())); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } return data; }
From source file:de.ks.file.FileStoreTest.java
@Before public void setUp() throws Exception { controller.startOrResume(new ActivityHint(AddThoughtActivity.class)); cleanup.cleanup();//from w ww. j av a 2s.c o m fileStoreDir = TMPDIR + File.separator + "idnadrevTestStore"; Options.store(fileStoreDir, FileOptions.class).getFileStoreDir(); File file = new File(fileStoreDir); if (file.exists()) { Files.walkFileTree(file.toPath(), new SimpleFileVisitor<Path>() { @Override 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.excelsiorjet.api.util.Utils.java
public static void copyDirectory(Path source, Path target) throws IOException { Files.walkFileTree(source, new FileVisitor<Path>() { @Override// ww w . ja va 2 s . c o m public FileVisitResult preVisitDirectory(Path subfolder, BasicFileAttributes attrs) throws IOException { Files.createDirectories(target.resolve(source.relativize(subfolder))); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException { Path targetFile = target.resolve(source.relativize(sourceFile)); copyFile(sourceFile, targetFile); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path sourceFile, IOException e) throws IOException { throw new IOException(Txt.s("Utils.CannotCopyFile.Error", sourceFile.toString(), e.getMessage()), e); } @Override public FileVisitResult postVisitDirectory(Path source, IOException ioe) throws IOException { return FileVisitResult.CONTINUE; } }); }