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


Java Files.walk方法代碼示例

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


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

示例1: getConfig

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
public Config getConfig() throws IOException {
  PathMatcher pathMatcher;

  try {
    pathMatcher = FileSystems.getDefault().getPathMatcher(inputFilePattern);
  } catch (IllegalArgumentException e) {
    throw new IllegalArgumentException(
        "Invalid input file pattern: " + inputFilePattern);
  }

  try (Stream<Path> pathStream = Files.walk(baseDirectory)) {
    return pathStream
        .filter(p -> Files.isRegularFile(p) && pathMatcher.matches(p))
        .map(p -> ConfigFactory.parseFile(p.toFile()))
        .reduce(ConfigFactory.empty(), Config::withFallback)
        .resolve(
            ConfigResolveOptions.defaults()
                .setAllowUnresolved(true)
                .setUseSystemEnvironment(false)
        );
  }
}
 
開發者ID:okvee,項目名稱:tscfg-docgen,代碼行數:24,代碼來源:PathMatcherConfigProvider.java

示例2: processSelf

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Processes the class files from the currently running JDK,
 * using the jrt: filesystem.
 *
 * @return true for success, false for failure
 * @throws IOException if an I/O error occurs
 */
boolean processSelf(Collection<String> classes) throws IOException {
    options.add("--add-modules");
    options.add("java.se.ee,jdk.xml.bind"); // TODO why jdk.xml.bind?

    if (classes.isEmpty()) {
        Path modules = FileSystems.getFileSystem(URI.create("jrt:/"))
                                  .getPath("/modules");

        // names are /modules/<modulename>/pkg/.../Classname.class
        try (Stream<Path> paths = Files.walk(modules)) {
            Stream<String> files =
                paths.filter(p -> p.getNameCount() > 2)
                     .map(p -> p.subpath(1, p.getNameCount()))
                     .map(Path::toString);
            return doModularFileNames(files);
        }
    } else {
        return doClassNames(classes);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Main.java

示例3: copyClasses

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Copy classes except the module-info.class to the destination directory
 */
public static void copyClasses(Path from, Path dest) throws IOException {
    try (Stream<Path> stream = Files.walk(from, Integer.MAX_VALUE)) {
        stream.filter(path -> !path.getFileName().toString().equals(MODULE_INFO) &&
            path.getFileName().toString().endsWith(".class"))
            .map(path -> from.relativize(path))
            .forEach(path -> {
                try {
                    Path newFile = dest.resolve(path);
                    Files.createDirectories(newFile.getParent());
                    Files.copy(from.resolve(path), newFile);
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            });
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:GenModuleInfo.java

示例4: compileAll

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Compiles all modules used by the test
 */
@BeforeTest
public void compileAll() throws Exception {
    CompilerUtils.cleanDir(MODS_DIR);
    CompilerUtils.cleanDir(LIBS_DIR);

    for (String mn : modules) {
        // compile a module
        assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, mn));

        // create JAR files with no module-info.class
        Path root = MODS_DIR.resolve(mn);
        try (Stream<Path> stream = Files.walk(root, Integer.MAX_VALUE)) {
            Stream<Path> entries = stream.filter(f -> {
                String fn = f.getFileName().toString();
                return fn.endsWith(".class") && !fn.equals("module-info.class");
            });
            JdepsUtil.createJar(LIBS_DIR.resolve(mn + ".jar"), root, entries);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TransitiveDeps.java

示例5: testWalkOneLevel

import java.nio.file.Files; //導入方法依賴的package包/類
public void testWalkOneLevel() {
    try (Stream<Path> s = Files.walk(testFolder, 1)) {
        Object[] actual = s.filter(path -> ! path.equals(testFolder))
                           .sorted()
                           .toArray();
        assertEquals(actual, level1);
    } catch (IOException ioe) {
        fail("Unexpected IOException");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:StreamTest.java

示例6: DirectoryIterator

import java.nio.file.Files; //導入方法依賴的package包/類
DirectoryIterator() throws IOException {
    List<Path> paths = null;
    try (Stream<Path> stream = Files.walk(path, Integer.MAX_VALUE)) {
        paths = stream.filter(ClassFileReader::isClass)
                      .collect(Collectors.toList());
    }
    this.entries = paths;
    this.index = 0;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:ClassFileReader.java

示例7: collectClassFile

import java.nio.file.Files; //導入方法依賴的package包/類
List<String> collectClassFile(Path root) throws IOException {
    try (Stream<Path> files = Files.walk(root)) {
        return files.filter(p -> Files.isRegularFile(p))
                    .filter(p -> p.getFileName().toString().endsWith(".class"))
                    .map(p -> root.relativize(p).toString())
                    .collect(Collectors.toList());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:CreateSymbolsTestImpl.java

示例8: gatherClasses

import java.nio.file.Files; //導入方法依賴的package包/類
private ResourcePool gatherClasses(Path module) throws Exception {
    ResourcePoolManager poolMgr = new ResourcePoolManager(ByteOrder.nativeOrder(), new StringTable() {

        @Override
        public int addString(String str) {
            return -1;
        }

        @Override
        public String getString(int id) {
            return null;
        }
    });

    ResourcePoolBuilder poolBuilder = poolMgr.resourcePoolBuilder();
    try (Stream<Path> stream = Files.walk(module)) {
        for (Iterator<Path> iterator = stream.iterator(); iterator.hasNext();) {
            Path p = iterator.next();
            if (Files.isRegularFile(p) && p.toString().endsWith(".class")) {
                byte[] content = Files.readAllBytes(p);
                poolBuilder.add(ResourcePoolEntry.create(p.toString(), content));
            }
        }
    }
    return poolBuilder.build();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:CompressorPluginTest.java

示例9: start

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * This method launches the CommunicationManager
 *
 * @throws IllegalArgumentException if communication.path is not set
 */
public void start() {
    String stringPath = getPathCommunication();
    if (stringPath == null) return;
    try (Stream<Path> paths = Files.walk(Paths.get(stringPath))) {
        paths.filter(Files::isRegularFile)
                .filter(file -> file.toString().endsWith(".jar"))
                .forEach((Path filePath) -> {
                    JarLoader jarLoader = JarLoader.createJarLoader(filePath.toString());
                    launchModule(jarLoader);
                });
    } catch (IOException e) {
        LOGGER.error(e.getMessage());
    }
    LOGGER.info("All ICommunication has been launched");
}
 
開發者ID:IKB4Stream,項目名稱:IKB4Stream,代碼行數:21,代碼來源:CommunicationManager.java

示例10: main

import java.nio.file.Files; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    String javaHome = args[0];
    FileSystem fs = null;
    boolean isInstalled = false;
    if (args.length == 2) {
        fs = createFsByInstalledProvider();
        isInstalled = true;
    } else {
        fs = createFsWithURLClassloader(javaHome);
    }

    Path mods = fs.getPath("/modules");
    try (Stream<Path> stream = Files.walk(mods)) {
        stream.forEach(path -> {
            path.getFileName();
        });
    } finally {
        try {
            fs.close();
        } catch (UnsupportedOperationException e) {
            if (!isInstalled) {
                throw new RuntimeException(
                    "UnsupportedOperationException is thrown unexpectedly");
            }
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:Main.java

示例11: clearDir

import java.nio.file.Files; //導入方法依賴的package包/類
private static boolean clearDir(Path path, Predicate<Path> disallowed) throws IOException {
	try (Stream<Path> stream = Files.walk(path, FileVisitOption.FOLLOW_LINKS)) {
		if (stream.anyMatch(disallowed)) return false;
	}

	AtomicBoolean ret = new AtomicBoolean(true);

	Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
		@Override
		public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
			if (disallowed.test(file)) {
				ret.set(false);

				return FileVisitResult.TERMINATE;
			} else {
				Files.delete(file);

				return FileVisitResult.CONTINUE;
			}
		}

		@Override
		public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
			if (exc != null) throw exc;
			if (!dir.equals(path)) Files.delete(dir);

			return FileVisitResult.CONTINUE;
		}
	});

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

示例12: getSourceFiles

import java.nio.file.Files; //導入方法依賴的package包/類
private List<SourceFile> getSourceFiles(Path basePath) throws IOException {
	try (Stream<Path> stream = Files.walk(basePath)) {
		return stream.filter(path -> path.getFileName().toString().endsWith(".java"))
			.map(path -> new FileSystemSourceFile(basePath, basePath.relativize(path)))
			.collect(Collectors.toList());
	}
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:8,代碼來源:TestRastComparator.java

示例13: getChartTgzs

import java.nio.file.Files; //導入方法依賴的package包/類
List<String> getChartTgzs(String path) throws MojoExecutionException {
	try (Stream<Path> files = Files.walk(Paths.get(path))) {
		return files.filter(p -> p.getFileName().toString().endsWith("tgz"))
				.map(p -> p.toString())
				.collect(Collectors.toList());
	} catch (IOException e) {
		throw new MojoExecutionException("Unable to scan repo directory at " + path, e);
	}
}
 
開發者ID:kiwigrid,項目名稱:helm-maven-plugin,代碼行數:10,代碼來源:AbstractHelmMojo.java

示例14: walk

import java.nio.file.Files; //導入方法依賴的package包/類
private Map<String, ModuleReference> walk(Path root) {
    try (Stream<Path> stream = Files.walk(root, 1)) {
        return stream.filter(path -> !path.equals(root))
                     .map(this::toModuleReference)
                     .collect(toMap(mref -> mref.descriptor().name(),
                                    Function.identity()));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:JdepsConfiguration.java

示例15: getMultipleChoiceImageResources

import java.nio.file.Files; //導入方法依賴的package包/類
public List<String> getMultipleChoiceImageResources(){
		final URI uri;
		final ArrayList<String> resourceList;
		final PathMatcher matcher;
		final Path myPath;
		final Stream<Path> walk;
		resourceList = new ArrayList<String>();
		matcher = FileSystems.getDefault().getPathMatcher(GlobFactoryHelper.getCaseInsensitiveExtensionGlob("PNG","JPG"));
		try {
			uri = ResourceHelper.getResource(isFromGameResourceInput(), gamePath, setPath).toURI();
			myPath= Paths.get(uri);
			walk = Files.walk(myPath, 3, FileVisitOption.FOLLOW_LINKS);
			for (Iterator<Path> it = walk.iterator(); it.hasNext();){
				Path currentPath =it.next();
				if (matcher.matches(currentPath))
				{		resourceList.add(currentPath.toString().substring(currentPath.toString().indexOf("game-resources-input/")));
				}
				}


		} catch (IOException | URISyntaxException e1) {
			log.error("Fail",e1);

		} 
		return resourceList;


		
		
		
		
/*		final String pattern;
		final String resourcePath;
		final List<String> resourceList; 
		pattern=GlobFactoryHelper.getCaseInsensitiveExtensionGlob("PNG","JPG");
		resourcePath= ResourceHelper.getResourceAddress( isFromGameResourceInput(),getGamePath(), getSetPath());
		resourceList= ImageFilesLoaderHelper.getImageResources(pattern, resourcePath, 3, log);
		return resourceList;
	*/
	}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:41,代碼來源:MultipleChoiceImageLoader.java


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