当前位置: 首页>>代码示例>>Java>>正文


Java FileVisitOption类代码示例

本文整理汇总了Java中java.nio.file.FileVisitOption的典型用法代码示例。如果您正苦于以下问题:Java FileVisitOption类的具体用法?Java FileVisitOption怎么用?Java FileVisitOption使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FileVisitOption类属于java.nio.file包,在下文中一共展示了FileVisitOption类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resolveConfig

import java.nio.file.FileVisitOption; //导入依赖的package包/类
static void resolveConfig(Environment env, final Settings.Builder settingsBuilder) {

        try {
            Files.walkFileTree(env.configFile(), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    String fileName = file.getFileName().toString();
                    if (fileName.startsWith("logging.")) {
                        for (String allowedSuffix : ALLOWED_SUFFIXES) {
                            if (fileName.endsWith(allowedSuffix)) {
                                loadConfig(file, settingsBuilder);
                                break;
                            }
                        }
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException ioe) {
            throw new ElasticsearchException("Failed to load logging configuration", ioe);
        }
    }
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:23,代码来源:LogConfigurator.java

示例2: validateFileSystemLoopException

import java.nio.file.FileVisitOption; //导入依赖的package包/类
private void validateFileSystemLoopException(Path start, Path... causes) {
    try (Stream<Path> s = Files.walk(start, FileVisitOption.FOLLOW_LINKS)) {
        try {
            int count = s.mapToInt(p -> 1).reduce(0, Integer::sum);
            fail("Should got FileSystemLoopException, but got " + count + "elements.");
        } catch (UncheckedIOException uioe) {
            IOException ioe = uioe.getCause();
            if (ioe instanceof FileSystemLoopException) {
                FileSystemLoopException fsle = (FileSystemLoopException) ioe;
                boolean match = false;
                for (Path cause: causes) {
                    if (fsle.getFile().equals(cause.toString())) {
                        match = true;
                        break;
                    }
                }
                assertTrue(match);
            } else {
                fail("Unexpected UncheckedIOException cause " + ioe.toString());
            }
        }
    } catch(IOException ex) {
        fail("Unexpected IOException " + ex);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:StreamTest.java

示例3: ArchiveContainer

import java.nio.file.FileVisitOption; //导入依赖的package包/类
public ArchiveContainer(Path archivePath) throws IOException, ProviderNotFoundException, SecurityException {
    this.archivePath = archivePath;
    if (multiReleaseValue != null && archivePath.toString().endsWith(".jar")) {
        Map<String,String> env = Collections.singletonMap("multi-release", multiReleaseValue);
        FileSystemProvider jarFSProvider = fsInfo.getJarFSProvider();
        Assert.checkNonNull(jarFSProvider, "should have been caught before!");
        this.fileSystem = jarFSProvider.newFileSystem(archivePath, env);
    } else {
        this.fileSystem = FileSystems.newFileSystem(archivePath, null);
    }
    packages = new HashMap<>();
    for (Path root : fileSystem.getRootDirectories()) {
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
                        if (isValid(dir.getFileName())) {
                            packages.put(new RelativeDirectory(root.relativize(dir).toString()), dir);
                            return FileVisitResult.CONTINUE;
                        } else {
                            return FileVisitResult.SKIP_SUBTREE;
                        }
                    }
                });
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:JavacFileManager.java

示例4: resolvePaths

import java.nio.file.FileVisitOption; //导入依赖的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

示例5: getFiles

import java.nio.file.FileVisitOption; //导入依赖的package包/类
@Override
@NonNull
public Iterable<JavaFileObject> getFiles(
        @NonNull String folderName,
        @NullAllowed final ClassPath.Entry entry,
        @NullAllowed final Set<JavaFileObject.Kind> kinds,
        @NullAllowed final JavaFileFilterImplementation filter,
        final boolean recursive) throws IOException {
    if (separator != FileObjects.NBFS_SEPARATOR_CHAR) {
        folderName = folderName.replace(FileObjects.NBFS_SEPARATOR_CHAR, separator);
    }
    final Path target = root.resolve(folderName);
    final List<JavaFileObject> res = new ArrayList<>();
    try (final Stream<Path> s = recursive ? Files.walk(target, FileVisitOption.FOLLOW_LINKS) : Files.list(target)) {
        s.filter((p)->{
            return (kinds == null || kinds.contains(FileObjects.getKind(FileObjects.getExtension(p.getFileName().toString()))))
                && Files.isRegularFile(p);
        })
        .forEach((p)->{res.add(FileObjects.pathFileObject(p, root, rootURI, null));});
    }
    return Collections.unmodifiableCollection(res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:PathArchive.java

示例6: setImages

import java.nio.file.FileVisitOption; //导入依赖的package包/类
private void setImages(Path path, ImageCompletionExercise exercise, Boolean dryRun) throws BuenOjoDataSetException{
	try {
		
		Set<SatelliteImage> images = new HashSet<>(maxImages);
		List<Path> imageList = Files.walk(path, 1, FileVisitOption.FOLLOW_LINKS).filter(p-> {
			return BuenOjoFileUtils.contentType(p).isPresent() && !BuenOjoFileUtils.contentType(p).get().equals("text/csv")  && !isPlaceholderImage(p);
			}).collect(Collectors.toList());
		
		for (Path imagePath : imageList) {
			
			String fileName = FilenameUtils.removeExtension(imagePath.getFileName().toString());
			Path csvPath = path.resolve(fileName + FilenameUtils.EXTENSION_SEPARATOR+ BuenOjoFileUtils.CSV_EXTENSION);
			
			SatelliteImage image = satelliteImageFactory.imageFromFile(BuenOjoFileUtils.multipartFile(imagePath), BuenOjoFileUtils.multipartFile(csvPath), dryRun);
			images.add(image);
			
		}
		exercise.setSatelliteImages(new HashSet<>(satelliteImageRepository.save(images)));
	} catch (BuenOjoCSVParserException | InvalidSatelliteImageType | BuenOjoFileException | IOException
			| BuenOjoInconsistencyException e) {
		throw new BuenOjoDataSetException(e.getMessage());
	}
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:24,代码来源:ImageCompletionLoader.java

示例7: loadExercisePhotos

import java.nio.file.FileVisitOption; //导入依赖的package包/类
private void loadExercisePhotos(ExerciseDataSetDTO dto, Boolean dryRun)
		throws IOException, BuenOjoDataSetException, BuenOjoFileException, BuenOjoInconsistencyException {

	Path picturesPath = Paths.get(dto.getPath(), picturesDir);
	ArrayList<PhotoLocationImage> pImages = new ArrayList<>();
	
	for (Path path : Files.walk(picturesPath, 1, FileVisitOption.FOLLOW_LINKS).collect(Collectors.toList())) {

		Optional<String> contentType = BuenOjoFileUtils.contentType(path);
		if (contentType.isPresent()) {
			ImageResource img = imageResourceService.createImageResource(null, BuenOjoFileUtils.multipartFile(path), dryRun);
			PhotoLocationImage pImg = PhotoLocationImage.fromImageResource(img);
			pImages.add(pImg);
		}
	}
	
	photoLocationImageRepository.save(pImages);
}
 
开发者ID:GastonMauroDiaz,项目名称:buenojo,代码行数:19,代码来源:PhotoLocationLoader.java

示例8: ElasticsearchTestServer

import java.nio.file.FileVisitOption; //导入依赖的package包/类
private ElasticsearchTestServer(Builder builder) {
    if (builder.cleanDataDir) {
        try {
            Path rootPath = Paths.get(builder.dataDirectory);
            if (Files.exists(rootPath)) {
                Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS)
                        .sorted(Comparator.reverseOrder())
                        .map(Path::toFile)
                        .forEach(File::delete);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Settings settings = Settings.builder()
            .put("client.transport.ignore_cluster_name", true)
            .put("transport.type", "netty4")
            .put("http.type", "netty4")
            .put("http.enabled", "true")
            .put("http.port", builder.httpPort)
            .put("path.home", builder.dataDirectory)
            .put("transport.tcp.port", builder.transportPort)
            .build();
    this.node = new MyNode(settings, Arrays.asList(Netty4Plugin.class));
}
 
开发者ID:tokenmill,项目名称:crawling-framework,代码行数:26,代码来源:ElasticsearchTestServer.java

示例9: getMapFolders

import java.nio.file.FileVisitOption; //导入依赖的package包/类
public Set<Path> getMapFolders(final Logger logger) throws IOException {
    final Set<Path> mapFolders = new HashSet<>();
    for(Path root : getRootPaths()) {
        int depth = "".equals(root.toString()) ? 0 : Iterables.size(root);
        Files.walkFileTree(getPath().resolve(root), ImmutableSet.of(FileVisitOption.FOLLOW_LINKS), maxDepth - depth, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                if(!isExcluded(dir)) {
                    if(MapFolder.isMapFolder(dir)) {
                        mapFolders.add(dir);
                    }
                    return FileVisitResult.CONTINUE;
                } else {
                    logger.fine("Skipping excluded path " + dir);
                    return FileVisitResult.SKIP_SUBTREE;
                }
            }
        });
    }
    return mapFolders;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:MapSource.java

示例10: countFiles

import java.nio.file.FileVisitOption; //导入依赖的package包/类
public static long countFiles(Path file)
{
	if( !Files.exists(file, LinkOption.NOFOLLOW_LINKS) )
	{
		return 0;
	}
	try
	{
		CountingVisitor visitor = new CountingVisitor();
		Files.walkFileTree(file, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor);
		return visitor.getCount();
	}
	catch( Exception e )
	{
		throw new RuntimeException("Error counting files for " + file.toString(), e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:18,代码来源:FileUtils.java

示例11: EurostagDDB

import java.nio.file.FileVisitOption; //导入依赖的package包/类
EurostagDDB(List<Path> ddbDirs) throws IOException {
    for (Path ddbDir : ddbDirs) {
        ddbDir = readSymbolicLink(ddbDir);
        if (!Files.exists(ddbDir) && !Files.isDirectory(ddbDir)) {
            throw new IllegalArgumentException(ddbDir + " must exist and be a dir");
        }
        Files.walkFileTree(ddbDir, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String fileName = file.getFileName().toString();
                Path tmpfile = readSymbolicLink(file);
                if (Files.isDirectory(tmpfile)) {
                    Files.walkFileTree(tmpfile, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, this);
                } else if (Files.isRegularFile(tmpfile) && fileName.endsWith(".tg")) {
                    String key = fileName.substring(0, fileName.length() - 3);
                    if (generators.containsKey(key)) {
                        LOGGER.warn("the processing has detected that the file {} is present in {} and {}", fileName, tmpfile, generators.get(key));
                    }
                    generators.put(key, tmpfile);
                }
                return super.visitFile(file, attrs);
            }
        });
    }
}
 
开发者ID:itesla,项目名称:ipst,代码行数:26,代码来源:EurostagDDB.java

示例12: listDerivateContentAsJson

import java.nio.file.FileVisitOption; //导入依赖的package包/类
private static String listDerivateContentAsJson(MCRDerivate derObj, String path, int depth, UriInfo info)
    throws IOException {
    StringWriter sw = new StringWriter();
    MCRPath root = MCRPath.getPath(derObj.getId().toString(), "/");
    root = MCRPath.toMCRPath(root.resolve(path));
    if (depth == -1) {
        depth = Integer.MAX_VALUE;
    }
    if (root != null) {
        JsonWriter writer = new JsonWriter(sw);
        Files.walkFileTree(root, EnumSet.noneOf(FileVisitOption.class), depth,
            new MCRJSONFileVisitor(writer, derObj.getOwnerID(), derObj.getId(), info));
        writer.close();
    }
    return sw.toString();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:17,代码来源:MCRRestAPIObjectsHelper.java

示例13: getLatestVersionSubfolder

import java.nio.file.FileVisitOption; //导入依赖的package包/类
/**
 * Returns the latest version subfolder of the specified module folder.
 * 
 * @param modFolder module folder to look latest version subfolder in
 * @return the latest version subfolder of the specified module folder or <code>null</code> if the specified module folder contains no folders that are
 *         valid version strings
 * @throws IOException if scanning the specified module folder throws an {@link IOException}
 */
public static Path getLatestVersionSubfolder( final Path modFolder ) throws IOException {
	// Holders because "final" is needed to be accessible from visitFile()
	// (I store the path too because version folder name is ambiguous (e.g. "1.0" and "1.0.0")
	final Holder< Path > latestVersionPath = new Holder<>();
	final Holder< VersionBean > latestVersion = new Holder<>();
	
	Files.walkFileTree( modFolder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() {
		@Override
		public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException {
			if ( !attrs.isDirectory() )
				return FileVisitResult.CONTINUE;
			
			final VersionBean version = VersionBean.fromString( file.getFileName().toString() );
			if ( version != null )
				if ( latestVersion.value == null || version.compareTo( latestVersion.value ) > 0 ) {
					latestVersion.value = version;
					latestVersionPath.value = file;
				}
			
			return FileVisitResult.CONTINUE;
		}
	} );
	
	return latestVersionPath.value;
}
 
开发者ID:icza,项目名称:scelight,代码行数:34,代码来源:Updater.java

示例14: getReleaseFile

import java.nio.file.FileVisitOption; //导入依赖的package包/类
/**
 * Returns the release file for the specified name prefix
 * 
 * @param folder folder in which to search
 * @param prefix file name prefix whose release file to return (the beginning of the file name)
 * @return the release file for the specified name prefix
 * @throws IOException if any error occurs during searching for the release file
 */
private static Path getReleaseFile( final Path folder, final String prefix ) throws IOException {
	final AtomicReference< Path > result = new AtomicReference<>();
	
	Files.walkFileTree( folder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() {
		@Override
		public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException {
			if ( attrs.isDirectory() )
				return FileVisitResult.CONTINUE;
			
			if ( file.getFileName().toString().startsWith( prefix ) ) {
				result.set( file );
				return FileVisitResult.TERMINATE;
			}
			
			return FileVisitResult.CONTINUE;
		}
	} );
	
	return result.get();
}
 
开发者ID:icza,项目名称:scelight,代码行数:29,代码来源:CreateModulesBean.java

示例15: correctBDPack

import java.nio.file.FileVisitOption; //导入依赖的package包/类
/**
 * Corrects the specified balance data pack.
 * 
 * @param webExportFolder base web export folder
 * @param outFolder output folder
 * @throws Exception if any error occurs
 */
private static void correctBDPack( final Path webExportFolder, final Path outFolder ) throws Exception {
	Files.createDirectories( outFolder.resolve( "enUS" ) );
	
	// First copy strings
	Files.copy( webExportFolder.resolve( "enUS/S2Strings.xml" ), outFolder.resolve( "enUS/S2Strings.xml" ) );
	
	Files.walkFileTree( webExportFolder, Collections.< FileVisitOption > emptySet(), 1, new SimpleFileVisitor< Path >() {
		@Override
		public FileVisitResult visitFile( final Path file, final BasicFileAttributes attrs ) throws IOException {
			if ( attrs.isDirectory() )
				return FileVisitResult.CONTINUE;
			
			processFile( file, outFolder );
			
			return FileVisitResult.CONTINUE;
		};
	} );
}
 
开发者ID:icza,项目名称:scelight,代码行数:26,代码来源:CorrectBalanceDataPacks.java


注:本文中的java.nio.file.FileVisitOption类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。