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


Java Files.list方法代碼示例

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


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

示例1: importAll

import java.nio.file.Files; //導入方法依賴的package包/類
private static void importAll(Path parent, Importer importer, List<ReadOnlyDataSource> dataSources) throws IOException {
    if (Files.isDirectory(parent)) {
        try (Stream<Path> stream = Files.list(parent)) {
            stream.sorted().forEach(child -> {
                if (Files.isDirectory(child)) {
                    try {
                        importAll(child, importer, dataSources);
                    } catch (IOException e) {
                        throw new UncheckedIOException(e);
                    }
                } else {
                    addDataSource(parent, child, importer, dataSources);
                }
            });
        }
    } else {
        if (parent.getParent() != null) {
            addDataSource(parent.getParent(), parent, importer, dataSources);
        }
    }
}
 
開發者ID:powsybl,項目名稱:powsybl-core,代碼行數:22,代碼來源:Importers.java

示例2: getFileNameList

import java.nio.file.Files; //導入方法依賴的package包/類
public static List<String> getFileNameList(Path path)
        throws IOException
{
    ImmutableList<String> fileNames;
    try (Stream<Path> stream = Files.list(path)) {
        fileNames = stream.filter(Files::isRegularFile)
                .map(Path::getFileName).map(Path::toString)
                .collect(toImmutableList());
    }
    return fileNames;
}
 
開發者ID:prestodb,項目名稱:presto-manager,代碼行數:12,代碼來源:AgentFileUtils.java

示例3: testKnownDirectories

import java.nio.file.Files; //導入方法依賴的package包/類
@Test(dataProvider = "knownDirectories")
public void testKnownDirectories(String path, boolean theDefault) throws Exception {
    if (isExplodedBuild && !theDefault) {
        System.out.println("Skip testKnownDirectories with non-default FileSystem");
        return;
    }

    FileSystem fs = selectFileSystem(theDefault);
    Path dir = fs.getPath(path);

    assertTrue(Files.isDirectory(dir));

    // directory should not be empty
    try (Stream<Path> stream = Files.list(dir)) {
        assertTrue(stream.count() > 0L);
    }
    try (Stream<Path> stream = Files.walk(dir)) {
        assertTrue(stream.count() > 0L);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:Basic.java

示例4: fileCompletions

import java.nio.file.Files; //導入方法依賴的package包/類
private static CompletionProvider fileCompletions(Predicate<Path> accept) {
    return (code, cursor, anchor) -> {
        int lastSlash = code.lastIndexOf('/');
        String path = code.substring(0, lastSlash + 1);
        String prefix = lastSlash != (-1) ? code.substring(lastSlash + 1) : code;
        Path current = toPathResolvingUserHome(path);
        List<Suggestion> result = new ArrayList<>();
        try (Stream<Path> dir = Files.list(current)) {
            dir.filter(f -> accept.test(f) && f.getFileName().toString().startsWith(prefix))
               .map(f -> new ArgSuggestion(f.getFileName() + (Files.isDirectory(f) ? "/" : "")))
               .forEach(result::add);
        } catch (IOException ex) {
            //ignore...
        }
        if (path.isEmpty()) {
            StreamSupport.stream(FileSystems.getDefault().getRootDirectories().spliterator(), false)
                         .filter(root -> Files.exists(root))
                         .filter(root -> accept.test(root) && root.toString().startsWith(prefix))
                         .map(root -> new ArgSuggestion(root.toString()))
                         .forEach(result::add);
        }
        anchor[0] = path.length();
        return result;
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:JShellTool.java

示例5: testUserHome

import java.nio.file.Files; //導入方法依賴的package包/類
@Test
public void testUserHome() throws IOException {
    List<String> completions;
    Path home = Paths.get(System.getProperty("user.home"));
    try (Stream<Path> content = Files.list(home)) {
        completions = content.filter(CLASSPATH_FILTER)
                             .map(file -> file.getFileName().toString() + (Files.isDirectory(file) ? "/" : ""))
                             .sorted()
                             .collect(Collectors.toList());
    }
    testNoStartUp(
            a -> assertCompletion(a, "/env --class-path ~/|", false, completions.toArray(new String[completions.size()]))
    );
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:CommandCompletionTest.java

示例6: addDirectory

import java.nio.file.Files; //導入方法依賴的package包/類
private void addDirectory(Path dir, boolean warn) {
    if (!Files.isDirectory(dir)) {
        if (warn) {
            log.warning(Lint.LintCategory.PATH,
                        Warnings.DirPathElementNotFound(dir));
        }
        return;
    }

    try (Stream<Path> s = Files.list(dir)) {
        s.filter(Locations.this::isArchive)
                .forEach(dirEntry -> addFile(dirEntry, warn));
    } catch (IOException ignore) {
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:Locations.java

示例7: testSnapshotWithMissingShardLevelIndexFile

import java.nio.file.Files; //導入方法依賴的package包/類
public void testSnapshotWithMissingShardLevelIndexFile() throws Exception {
    Path repo = randomRepoPath();
    logger.info("-->  creating repository at {}", repo.toAbsolutePath());
    assertAcked(client().admin().cluster().preparePutRepository("test-repo").setType("fs").setSettings(
        Settings.builder().put("location", repo).put("compress", false)));

    createIndex("test-idx-1", "test-idx-2");
    logger.info("--> indexing some data");
    indexRandom(true,
        client().prepareIndex("test-idx-1", "doc").setSource("foo", "bar"),
        client().prepareIndex("test-idx-2", "doc").setSource("foo", "bar"));

    logger.info("--> creating snapshot");
    client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1")
        .setWaitForCompletion(true).setIndices("test-idx-*").get();

    logger.info("--> deleting shard level index file");
    try (Stream<Path> files = Files.list(repo.resolve("indices"))) {
        files.forEach(indexPath ->
            IOUtils.deleteFilesIgnoringExceptions(indexPath.resolve("0").resolve("index-0"))
        );
    }

    logger.info("--> creating another snapshot");
    CreateSnapshotResponse createSnapshotResponse =
        client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-2")
            .setWaitForCompletion(true).setIndices("test-idx-1").get();
    assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0));
    assertEquals(createSnapshotResponse.getSnapshotInfo().successfulShards(), createSnapshotResponse.getSnapshotInfo().totalShards());

    logger.info("--> restoring the first snapshot, the repository should not have lost any shard data despite deleting index-N, " +
                    "because it should have iterated over the snap-*.data files as backup");
    client().admin().indices().prepareDelete("test-idx-1", "test-idx-2").get();
    RestoreSnapshotResponse restoreSnapshotResponse =
        client().admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap-1").setWaitForCompletion(true).get();
    assertEquals(0, restoreSnapshotResponse.getRestoreInfo().failedShards());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:38,代碼來源:SharedClusterSnapshotRestoreIT.java

示例8: verifyFileMatching

import java.nio.file.Files; //導入方法依賴的package包/類
@Test
public void verifyFileMatching ()
		throws Exception {
	try (Stream<Path> pathStream = Files.list( new File( "/java" ).toPath() )) {
		Optional<Path> deploymentCheck = pathStream
			.filter( path -> path.getFileName().toString().endsWith( ".bat" ) )
			.findFirst();

		// logger.info( "object: {} : value: {}", deploymentCheck,
		// deploymentCheck.get() );
	}

}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:14,代碼來源:SimpleTests.java

示例9: listFiles

import java.nio.file.Files; //導入方法依賴的package包/類
private List<String> listFiles(Path path, Predicate<? super Path> filter) throws IOException {
    try (Stream<Path> stream = Files.list(path)) {
        return stream.filter(filter)
                     .map(p -> p.getFileName().toString() + (Files.isDirectory(p) ? "/" : ""))
                     .sorted()
                     .collect(Collectors.toList());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:CommandCompletionTest.java

示例10: list

import java.nio.file.Files; //導入方法依賴的package包/類
private Stream<Path> list(Path source) {
	try {
		return Files.list(source);
	} catch (IOException e) {
		validator.handleIOException(e);
		return null;
	}
}
 
開發者ID:JPDSousa,項目名稱:rookit-core,代碼行數:9,代碼來源:TrackParserGenerator.java

示例11: currentVersion

import java.nio.file.Files; //導入方法依賴的package包/類
private long currentVersion(StreamId streamId) {
    try (Stream<Path> stream = Files.list(directory)) {
        return stream
                .filter(p -> p.getFileName().toString().endsWith(dataSuffix))
                .filter(p -> FilenameCodec.parse(p, (timestamp, fileStreamId, eventNumber, eventType) -> fileStreamId.equals(streamId)))
                .count() - 1;
    } catch (IOException e) {
        throw new RuntimeException("Unable to count files in " + directory);
    }
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:11,代碼來源:FlatFilesystemEventStreamWriter.java

示例12: currentGlobalVersion

import java.nio.file.Files; //導入方法依賴的package包/類
private long currentGlobalVersion() {
    try (Stream<Path> stream = Files.list(directory)) {
        return stream.filter(p -> p.getFileName().toString().endsWith(dataSuffix)).count();
    } catch (IOException e) {
        throw new RuntimeException("Unable to count files in " + directory);
    }
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:8,代碼來源:FlatFilesystemEventStreamWriter.java

示例13: streamExists

import java.nio.file.Files; //導入方法依賴的package包/類
boolean streamExists(StreamId streamId) {
    try (Stream<Path> stream = Files.list(directory)) {
        return stream
                .filter(p -> p.getFileName().toString().endsWith(dataSuffix))
                .anyMatch(p -> FilenameCodec.parse(p, (timestamp, fileStreamId, eventNumber, eventType) -> fileStreamId.equals(streamId)));
    } catch (IOException e) {
        throw new RuntimeException("Unable to count files in " + directory);
    }
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:10,代碼來源:FlatFilesystemEventReader.java

示例14: truncateStoreFiles

import java.nio.file.Files; //導入方法依賴的package包/類
private void truncateStoreFiles(String storeName) {
  try {
    Stream<Path> list = Files.list(new File(".").toPath());
    Object[] paths = list.toArray();
    for (Object path : paths) {
      if (path.toString().contains(storeName)) {
        Files.write((Path) path, new byte[0], StandardOpenOption.TRUNCATE_EXISTING);
      }
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:14,代碼來源:MTableDUnitConfigFramework.java

示例15: findFirst

import java.nio.file.Files; //導入方法依賴的package包/類
static Path findFirst(Path basedir, String glob) throws IOException {
  PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob);
  try (Stream<Path> stream = Files.list(basedir)) {
    return stream
      .filter(matcher::matches)
      .findFirst()
      .orElseThrow(() -> new FileNotFoundException(basedir + "/.../" + glob));
  }
}
 
開發者ID:instalint-org,項目名稱:instalint,代碼行數:10,代碼來源:PluginFileLocator.java


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