當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。