當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.find方法代碼示例

本文整理匯總了Java中java.nio.file.Files.find方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.find方法的具體用法?Java Files.find怎麽用?Java Files.find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.find方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: resolvePaths

import java.nio.file.Files; //導入方法依賴的package包/類
private static List<Path> resolvePaths(List<Path> inputDirs, List<InputFile> inputFiles) throws IOException {
	List<Path> ret = new ArrayList<>(inputFiles.size());

	for (InputFile inputFile : inputFiles) {
		boolean found = false;

		for (Path inputDir : inputDirs) {
			try (Stream<Path> matches = Files.find(inputDir, Integer.MAX_VALUE, (path, attr) -> inputFile.equals(path), FileVisitOption.FOLLOW_LINKS)) {
				Path file = matches.findFirst().orElse(null);

				if (file != null) {
					ret.add(file);
					found = true;
					break;
				}
			} catch (UncheckedIOException e) {
				throw e.getCause();
			}
		}

		if (!found) throw new IOException("can't find input "+inputFile.getFileName());
	}

	return ret;
}
 
開發者ID:sfPlayer1,項目名稱:Matcher,代碼行數:26,代碼來源:Matcher.java

示例2: calculateServerClasspath

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Calculates the server classpath, which is a colon-delimited string of directories and .jar files.
 * @param baseLibDir    The base directory of server libs and classes
 * @return The classpath
 */
private static String calculateServerClasspath(String baseLibDir) {
    try {
        Path baseLibPath = Paths.get(baseLibDir).toAbsolutePath().normalize();
        Stream<Path> jars = Files.find(baseLibPath, 1, (path, attrs) -> path.toString().endsWith(".jar"));
        StringJoiner joiner = new StringJoiner(":");

        // server libs directory (containing the server Java classes)
        joiner.add(baseLibPath.toString());

        // all .jar files in the same directory
        jars.forEach((path) -> joiner.add(path.toString()));

        return joiner.toString();

    } catch (IOException ex) {
        String message = "Error resolving server base lib dir: " + ex.getMessage();
        logger.error(message, ex);
        throw new IllegalArgumentException(message, ex);
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:26,代碼來源:DataServerManager.java

示例3: readEnigma

import java.nio.file.Files; //導入方法依賴的package包/類
public static void readEnigma(Path dir, IMappingAcceptor mappingAcceptor) throws IOException {
	try (Stream<Path> stream = Files.find(dir,
			Integer.MAX_VALUE,
			(path, attr) -> attr.isRegularFile() && path.getFileName().toString().endsWith(".mapping"),
			FileVisitOption.FOLLOW_LINKS)) {
		stream.forEach(file -> readEnigmaFile(file, mappingAcceptor));
	} catch (UncheckedIOException e) {
		throw e.getCause();
	}
}
 
開發者ID:sfPlayer1,項目名稱:Matcher,代碼行數:11,代碼來源:MappingReader.java

示例4: searchFilesDir

import java.nio.file.Files; //導入方法依賴的package包/類
public String searchFilesDir(String filePath, String extension) throws IOException{
	Path root = Paths.get(filePath);
	int depth = 3;
	Stream<Path> searchStream = Files.find(root, depth, (path, attr) ->
	        String.valueOf(path).endsWith(extension));
	String found = searchStream
	        .sorted()
	        .map(String::valueOf)
	        .collect(Collectors.joining(" / "));
	searchStream.close();
	return found;
}
 
開發者ID:PacktPublishing,項目名稱:Spring-5.0-Cookbook,代碼行數:13,代碼來源:EmployeeFileStreamService.java

示例5: fromDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Creates a {@link List} of upsert {@link Change}s from all files under the specified directory
 * recursively.
 *
 * @param sourcePath the path to the import directory
 * @param targetPath the target directory path of the imported {@link Change}s
 *
 * @throws IOError if I/O error occurs
 */
static List<Change<?>> fromDirectory(Path sourcePath, String targetPath) {
    requireNonNull(sourcePath, "sourcePath");
    validateDirPath(targetPath, "targetPath");

    if (!Files.isDirectory(sourcePath)) {
        throw new IllegalArgumentException("sourcePath: " + sourcePath + " (must be a directory)");
    }

    final String finalTargetPath;
    if (!targetPath.endsWith("/")) {
        finalTargetPath = targetPath + '/';
    } else {
        finalTargetPath = targetPath;
    }

    try (Stream<Path> s = Files.find(sourcePath, Integer.MAX_VALUE, (p, a) -> a.isRegularFile())) {
        final int baseLength = sourcePath.toString().length() + 1;
        return s.map(sourceFilePath -> {
            final String targetFilePath =
                    finalTargetPath +
                    sourceFilePath.toString().substring(baseLength).replace(File.separatorChar, '/');

            return fromFile(sourceFilePath, targetFilePath);
        }).collect(Collectors.toList());
    } catch (IOException e) {
        throw new IOError(e);
    }
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:38,代碼來源:Change.java

示例6: findDataSetFiles

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * @return XML files representing individual data sets (XML files under named following pattern P00000.xml)
 */
private Stream<Path> findDataSetFiles(final Path publishingPackagesDir) {
    try {
        return Files.find(
            publishingPackagesDir,
            Integer.MAX_VALUE,
            (path, basicFileAttributes) -> basicFileAttributes.isRegularFile()
                && path.getFileName().toString().matches("P\\d+.xml")
        );

    } catch (final IOException e) {
        throw new UncheckedIOException("Failed to find codeBook files.", e);
    }
}
 
開發者ID:NHS-digital-website,項目名稱:hippo,代碼行數:17,代碼來源:GenerateNesstarImportContentTask.java

示例7: updateUserScripts

import java.nio.file.Files; //導入方法依賴的package包/類
public static void updateUserScripts() {
    if (!Files.exists(user_path) || !Files.isDirectory(user_path)) {
        return;
    }
    try (Stream<Path> user_scripts = Files.find(user_path, 1, (f, attr) -> {
        return f.toAbsolutePath().toString().endsWith(".fmoka") && Files.isRegularFile(f);
    })) {
        for (Iterator<Path> it = user_scripts.iterator(); it.hasNext();) {
            Path p = it.next();
            String id = p.toFile().getName();
            id = id.substring(0, id.length() - 6);
            Script scr = get(id);
            long last_time = Files.getLastModifiedTime(p).toMillis();
            if (scr == null) {
                scr = new Script(id, p);
                scr.setLastTime(last_time);
                load(scr);
            } else {
                if (scr.getLastTime() < last_time) {
                    if (scr.getStatus() == Status.LOADED) {
                        scr.setStatus(Status.UPDATED);
                    }
                    if (scr.getStatus() == Status.ERRORED) {
                        scr.setStatus(Status.UNLOADED);
                    }
                    scr.setLastTime(last_time);
                }
            }
        }
    } catch (IOException e) {
        System.out.println("Error updating user scripts");
        e.printStackTrace();
    }
}
 
開發者ID:Deamon5550,項目名稱:VoxelScript,代碼行數:35,代碼來源:ScriptManager.java

示例8: testFind

import java.nio.file.Files; //導入方法依賴的package包/類
public void testFind() throws IOException {
    PathBiPredicate pred = new PathBiPredicate((path, attrs) -> true);

    try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) {
        Set<Path> result = s.collect(Collectors.toCollection(TreeSet::new));
        assertEquals(pred.visited(), all);
        assertEquals(result.toArray(new Path[0]), pred.visited());
    }

    pred = new PathBiPredicate((path, attrs) -> attrs.isSymbolicLink());
    try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) {
        s.forEach(path -> assertTrue(Files.isSymbolicLink(path)));
        assertEquals(pred.visited(), all);
    }

    pred = new PathBiPredicate((path, attrs) ->
        path.getFileName().toString().startsWith("e"));
    try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) {
        s.forEach(path -> assertEquals(path.getFileName().toString(), "empty"));
        assertEquals(pred.visited(), all);
    }

    pred = new PathBiPredicate((path, attrs) ->
        path.getFileName().toString().startsWith("l") && attrs.isRegularFile());
    try (Stream<Path> s = Files.find(testFolder, Integer.MAX_VALUE, pred)) {
        s.forEach(path -> fail("Expect empty stream"));
        assertEquals(pred.visited(), all);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:30,代碼來源:StreamTest.java

示例9: testStreamCreateByFiles

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * java.nio.file.Files 提供的幾種創建文件,路徑流,部分參數傳null
 */
@Test
public void testStreamCreateByFiles() throws IOException {
    Stream<String> lines = Files.lines(Paths.get(""));
    Stream<Path> pathStream = Files.find(Paths.get(""), 10, null, null);
    Stream<Path> walk = Files.walk(null, null);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:10,代碼來源:StreamCreateDemo.java

示例10: packages

import java.nio.file.Files; //導入方法依賴的package包/類
private Set<String> packages(Path dir) {
    try (Stream<Path> stream = Files.find(dir, Integer.MAX_VALUE,
                         ((path, attrs) -> attrs.isRegularFile() &&
                                           path.toString().endsWith(".class")))) {
        return stream.map(path -> toPackageName(dir.relativize(path)))
                     .filter(pkg -> pkg.length() > 0)   // module-info
                     .distinct()
                     .collect(Collectors.toSet());
    } catch (IOException x) {
        throw new UncheckedIOException(x);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:GenModuleInfo.java

示例11: findFilesMatching

import java.nio.file.Files; //導入方法依賴的package包/類
private static Stream<Path> findFilesMatching(final Path directory, final String syntaxAndPattern)
    throws IOException {
  final PathMatcher matcher = directory.getFileSystem().getPathMatcher(syntaxAndPattern);
  return Files.find(
      directory, Integer.MAX_VALUE, (p, a) -> matcher.matches(p) && !a.isDirectory());
}
 
開發者ID:spotify,項目名稱:bazel-tools,代碼行數:7,代碼來源:Main.java

示例12: createJARFiles

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Create JAR files with no module-info.class
 */
public static List<Path> createJARFiles(Path mods, Path libs) throws IOException {
    Files.createDirectory(libs);

    for (String mn : MODULES) {
        Path root = mods.resolve(mn);
        Path msrc = SRC_DIR.resolve(mn);
        Path metaInf = msrc.resolve("META-INF");
        if (Files.exists(metaInf)) {
            try (Stream<Path> resources = Files.find(metaInf, Integer.MAX_VALUE,
                    (p, attr) -> { return attr.isRegularFile();})) {
                resources.forEach(file -> {
                    try {
                        Path path = msrc.relativize(file);
                        Files.createDirectories(root.resolve(path).getParent());
                        Files.copy(file, root.resolve(path));
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                });
            }
        }
        // copy all entries except module-info.class
        try (Stream<Path> stream = Files.find(root, Integer.MAX_VALUE,
                (p, attr) -> { return attr.isRegularFile();})) {
            Stream<Path> entries = stream.filter(f -> {
                String fn = f.getFileName().toString();
                if (fn.endsWith(".class")) {
                    return !fn.equals("module-info.class");
                } else {
                    return true;
                }
            });

            JdepsUtil.createJar(libs.resolve(mn + ".jar"), root, entries);
        }
    }

   return MODULES.stream()
            .map(mn -> LIBS_DIR.resolve(mn + ".jar"))
            .collect(Collectors.toList());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:45,代碼來源:GenModuleInfo.java


注:本文中的java.nio.file.Files.find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。