当前位置: 首页>>代码示例>>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;未经允许,请勿转载。