Java Code Examples for java.nio.file.FileVisitResult#TERMINATE

The following examples show how to use java.nio.file.FileVisitResult#TERMINATE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AssembleUtil.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
/**
 * Recursively process each sub-path of the specified directory.
 *
 * @param dir The directory to process.
 * @param function The function defining the test process, which returns a
 *          {@link FileVisitResult} to direct the recursion process.
 * @return A {@link FileVisitResult} to direct the recursion process.
 */
public static FileVisitResult recurseDir(final File dir, final Function<File,FileVisitResult> function) {
  final File[] files = dir.listFiles();
  if (files != null) {
    for (final File file : files) {
      final FileVisitResult result = recurseDir(file, function);
      if (result == FileVisitResult.SKIP_SIBLINGS)
        break;

      if (result == FileVisitResult.TERMINATE)
        return result;

      if (result == FileVisitResult.SKIP_SUBTREE)
        return FileVisitResult.SKIP_SIBLINGS;
    }
  }

  return function.apply(dir);
}
 
Example 2
Source File: DirectoryManifest.java    From genie with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FileVisitResult visitFileFailed(final Path file, final IOException ioe) {
    if (ioe instanceof FileSystemLoopException) {
        log.warn("Detected file system cycle visiting while visiting {}. Skipping.", file);
        return FileVisitResult.SKIP_SUBTREE;
    } else if (ioe instanceof AccessDeniedException) {
        log.warn("Access denied for file {}. Skipping", file);
        return FileVisitResult.SKIP_SUBTREE;
    } else if (ioe instanceof NoSuchFileException) {
        log.warn("File or directory disappeared while visiting {}. Skipping", file);
        return FileVisitResult.SKIP_SUBTREE;
    } else {
        log.error("Got unknown error {} while visiting {}. Terminating visitor", ioe.getMessage(), file, ioe);
        // TODO: Not sure if we should do this or skip subtree or just continue and ignore it?
        return FileVisitResult.TERMINATE;
    }
}
 
Example 3
Source File: ScmStubDownloaderBuilder.java    From spring-cloud-contract with Apache License 2.0 6 votes vote down vote up
private FileVisitResult latestVersionFromFolders(Path dir, File[] files) {
	List<DefaultArtifactVersionWrapper> versions = pickLatestVersion(files);
	if (versions.isEmpty()) {
		if (log.isDebugEnabled()) {
			log.debug("Not a single version matching semver for path ["
					+ dir.toAbsolutePath().toString() + "] was found");
		}
		return FileVisitResult.CONTINUE;
	}
	// 2.0.0.RELEASE, 2.0.0.BUILD-SNAPSHOT
	// 2.0.0.RELEASE
	DefaultArtifactVersionWrapper latestFoundVersion = versions
			.get(versions.size() - 1);
	latestFoundVersion = replaceWithSnapshotIfSameVersions(versions,
			latestFoundVersion);
	this.foundFile = latestFoundVersion.file.toPath();
	return FileVisitResult.TERMINATE;
}
 
Example 4
Source File: Finder.java    From XHAIL with GNU General Public License v3.0 6 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
	Objects.nonNull(file);
	Objects.nonNull(attrs);
	Path found = file.getFileName();
	for (String name : matchers.keySet())
		if (!results.containsKey(name)) {
			PathMatcher matcher = matchers.get(name);
			if (null != found && matcher.matches(found) && Files.isExecutable(file) && check(file, name, version)) {
				results.put(name, file);
				if (results.size() == matchers.size())
					return FileVisitResult.TERMINATE;
			}
		}
	return FileVisitResult.CONTINUE;
}
 
Example 5
Source File: GoPackagesVisitor.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) throws IOException {
	String fileName = filePath.getFileName().toString();
	if(!attrs.isDirectory() && fileName.endsWith(".go") && !isIgnoredName(fileName)) {
		this.hasGoSourceFiles = true;
		return FileVisitResult.TERMINATE;
	}
	return FileVisitResult.CONTINUE;
}
 
Example 6
Source File: FeatureXMLGetVersionVisitor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes arg1) throws IOException {
	FileSystem fileSystem = FileSystems.getDefault();
	PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern);

	if (pathMatcher.matches(path.getFileName())) {
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		try {
			DocumentBuilder builder = factory.newDocumentBuilder();
			Document doc = builder.parse(path.toFile());

			XPathFactory xpathfactory = XPathFactory.newInstance();
			XPath xpath = xpathfactory.newXPath();

			XPathExpression expr = xpath.compile("string(//feature[1]/@version)");
			Object result = expr.evaluate(doc, XPathConstants.STRING);
			if (result instanceof String) {
				this.version = result.toString();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return FileVisitResult.TERMINATE;
	}
	return FileVisitResult.CONTINUE;
}
 
Example 7
Source File: ApkChannelUtil.java    From MutiChannelPackup with Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
	if (matcher.matches(file)) {
		channelFile = file;
		return FileVisitResult.TERMINATE;
	} else {
		return FileVisitResult.CONTINUE;
	}
}
 
Example 8
Source File: RestartableJenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
    if (exc instanceof FileNotFoundException) {
        LOGGER.log(Level.FINE, "File not found while trying to copy to new home, continuing anyway: "+file.toString());
        return FileVisitResult.CONTINUE;
    } else {
        LOGGER.log(Level.WARNING, "Error copying file", exc);
        return FileVisitResult.TERMINATE;
    }
}
 
Example 9
Source File: CheckSrcFolderRootFilesWithNoPackage.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
	if(startDir == null) {
		this.startDir = dir;
		return super.preVisitDirectory(dir, attrs);
	} else {
		return FileVisitResult.TERMINATE; // Start directory only
	}
}
 
Example 10
Source File: MCRUploadHandlerIFS.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
    FileVisitResult result = super.postVisitDirectory(dir, exc);
    if (mainFile != null) {
        return FileVisitResult.TERMINATE;
    }
    return result;
}
 
Example 11
Source File: QueryCommandIntegrationTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) {
  if (path.toString().contains("parser-profiler")) {
    profilerPath = path;
    return FileVisitResult.TERMINATE;
  } else {
    return FileVisitResult.CONTINUE;
  }
}
 
Example 12
Source File: CheckSrcFolderRootFilesWithNoPackage.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
	if(file.getFileName().toString().endsWith(".go")) {
		containsGoSources = true;
		return FileVisitResult.TERMINATE;
	}
	return FileVisitResult.CONTINUE;
}
 
Example 13
Source File: ResourceHelper.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
	if (dir.endsWith(resource)) {
		this.result = dir.toFile().toURI().toURL();
		return FileVisitResult.TERMINATE;
	}
	return FileVisitResult.CONTINUE;
}
 
Example 14
Source File: ResourceHelper.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
	if (file.endsWith(resource)) {
		this.result = file.toFile().toURI().toURL();
		return FileVisitResult.TERMINATE;
	}
	return FileVisitResult.CONTINUE;
}
 
Example 15
Source File: Resources.java    From es6draft with MIT License 5 votes vote down vote up
@Override
public FileVisitResult visitFile(PATH path, BasicFileAttributes attrs) throws IOException {
    Path file = basedir.relativize(path);
    if (attrs.isRegularFile() && attrs.size() != 0L && fileMatcher.matches(file)) {
        return FileVisitResult.CONTINUE;
    }
    return FileVisitResult.TERMINATE;
}
 
Example 16
Source File: DiskJobFileServiceImpl.java    From genie with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public FileVisitResult visitFileFailed(final Path file, final IOException exc) throws IOException {
    // TODO: What do we think best course of action here is
    return FileVisitResult.TERMINATE;
}
 
Example 17
Source File: Tools.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException ioe)
        throws IOException {
    this.exception = ioe;
    return FileVisitResult.TERMINATE;
}
 
Example 18
Source File: AcronymVectorOfflineTrainer.java    From biomedicus with Apache License 2.0 4 votes vote down vote up
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attr) throws IOException {
  if (file.getFileName().toString().startsWith(".")) {
    return FileVisitResult.CONTINUE;
  }
  // Files that are larger than 100 MB should not be read all at once
  if (file.toFile().length() < 100000000) {
    Scanner scanner = new Scanner(file.toFile()).useDelimiter("\\Z");
    String fileText = scanner.next();
    scanner.close();
    if (vectorizeNotCount) {
      vectorizeChunk(fileText);
    } else {
      countChunk(fileText);
      bytesWordCounted += fileText.length();
      if (bytesWordCounted >= maxBytesToCountWords) {
        LOGGER.info("Done counting words.");
        return FileVisitResult.TERMINATE;
      }
    }
  } else {
    // Make virtual files out of this file, splitting on whitespace every ~10 MB
    BufferedReader reader = new BufferedReader(new FileReader(file.toFile()));
    char[] chunk = new char[10000000];
    long totalLength = 0;
    while (reader.read(chunk) > 0) {
      StringBuilder lineBuilder = new StringBuilder(new String(chunk));
      while (true) {
        // This could be sped up--reading bytes one at a time is fantastically slow
        int nextByte = reader.read();
        char nextChar = (char) nextByte;
        if (nextByte < 0 || nextChar == ' ' || nextChar == '\t' || nextChar == '\n') {
          break;
        }
        lineBuilder.append((char) nextByte);
      }
      String line = lineBuilder.toString();
      totalLength += line.length();
      if (vectorizeNotCount) {
        vectorizeChunk(line);
      } else {
        countChunk(line);
        LOGGER.info(wordFrequency.size() + " total words found");
        bytesWordCounted += line.length();
        if (bytesWordCounted >= maxBytesToCountWords) {
          LOGGER.info("Done counting words.");
          return FileVisitResult.TERMINATE;
        }
      }
      LOGGER.info(totalLength + " bytes of large file " + file + " processed");
    }
    reader.close();
  }

  LOGGER.trace(file + " visited");

  visited++;
  if (visited % 1000 == 0) {
    LOGGER.info("Visited {} of {}", visited, total);
  }

  return FileVisitResult.CONTINUE;
}
 
Example 19
Source File: MeasuresAnnotationTool.java    From biomedicus with Apache License 2.0 4 votes vote down vote up
private FileVisitResult runFile(Scanner scanner) throws IOException {
  System.out.println("File: " + relativePath.toString());

  REDO:
  while (true) {
    ExampleQuery exampleQuery = new ExampleQuery(examples);

    if (!exampleQuery.readAndPrintNextContext(bufferedReader)) {
      if (prev != null) {
        bufferedWriter.write(prev);
        bufferedWriter.newLine();
      }
      break;
    }
    System.out.flush();

    while (true) {
      String s = exampleQuery.tryCollect(scanner);
      if (s != null) {
        if (prev != null) {
          bufferedWriter.write(prev);
          bufferedWriter.newLine();
        }
        prev = s;
        break;
      }

      if (exampleQuery.redo) {
        prev = null;
        examples--;
        bufferedReader.close();
        openReader();
        continue REDO;
      }

      if (exampleQuery.quit) {
        if (prev != null) {
          bufferedWriter.write(prev);
          bufferedWriter.newLine();
        }
        return FileVisitResult.TERMINATE;
      }
    }

    System.out.println();
    examples++;
  }
  examples = 0;

  return FileVisitResult.CONTINUE;
}
 
Example 20
Source File: AtriumTools.java    From atrium-odl with Apache License 2.0 4 votes vote down vote up
@Override
public FileVisitResult visitFileFailed(Path file, IOException ioe) throws IOException {
	this.exception = ioe;
	return FileVisitResult.TERMINATE;
}