本文整理了Java中org.apache.beam.sdk.io.FileSystems.copy()
方法的一些代码示例,展示了FileSystems.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileSystems.copy()
方法的具体详情如下:
包路径:org.apache.beam.sdk.io.FileSystems
类名称:FileSystems
方法名:copy
[英]Copies a List of file-like resources from one location to another.
The number of source resources must equal the number of destination resources. Destination resources will be created recursively.
srcResourceIds and destResourceIds must have the same scheme.
It doesn't support copying globs.
[中]将类似文件的资源列表从一个位置复制到另一个位置。
源资源的数量必须等于目标资源的数量。目标资源将以递归方式创建。
SrcResourceId和DestresourceId必须具有相同的方案。
它不支持复制全局。
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@Test
public void testCopyIgnoreMissingFiles() throws Exception {
Path srcPath1 = temporaryFolder.newFile().toPath();
Path nonExistentPath = srcPath1.resolveSibling("non-existent");
Path srcPath3 = temporaryFolder.newFile().toPath();
Path destPath1 = srcPath1.resolveSibling("dest1");
Path destPath2 = nonExistentPath.resolveSibling("dest2");
Path destPath3 = srcPath1.resolveSibling("dest3");
createFileWithContent(srcPath1, "content1");
createFileWithContent(srcPath3, "content3");
FileSystems.copy(
toResourceIds(
ImmutableList.of(srcPath1, nonExistentPath, srcPath3), false /* isDirectory */),
toResourceIds(ImmutableList.of(destPath1, destPath2, destPath3), false /* isDirectory */),
MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES);
assertTrue(srcPath1.toFile().exists());
assertTrue(srcPath3.toFile().exists());
assertThat(
Files.readLines(srcPath1.toFile(), StandardCharsets.UTF_8), containsInAnyOrder("content1"));
assertFalse(destPath2.toFile().exists());
assertThat(
Files.readLines(srcPath3.toFile(), StandardCharsets.UTF_8), containsInAnyOrder("content3"));
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-google-cloud-platform
@Override
public void startLoadJob(JobReference jobRef, JobConfigurationLoad loadConfig)
throws IOException {
synchronized (allJobs) {
verifyUniqueJobId(jobRef.getJobId());
Job job = new Job();
job.setJobReference(jobRef);
job.setConfiguration(new JobConfiguration().setLoad(loadConfig));
job.setKind(" bigquery#job");
job.setStatus(new JobStatus().setState("PENDING"));
// Copy the files to a new location for import, as the temporary files will be deleted by
// the caller.
if (loadConfig.getSourceUris().size() > 0) {
ImmutableList.Builder<ResourceId> sourceFiles = ImmutableList.builder();
ImmutableList.Builder<ResourceId> loadFiles = ImmutableList.builder();
for (String filename : loadConfig.getSourceUris()) {
sourceFiles.add(FileSystems.matchNewResource(filename, false /* isDirectory */));
loadFiles.add(
FileSystems.matchNewResource(
filename + ThreadLocalRandom.current().nextInt(), false /* isDirectory */));
}
FileSystems.copy(sourceFiles.build(), loadFiles.build());
filesForLoadJobs.put(jobRef.getProjectId(), jobRef.getJobId(), loadFiles.build());
}
allJobs.put(jobRef.getProjectId(), jobRef.getJobId(), new JobInfo(job));
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@Test
public void testCopyThrowsNoSuchFileException() throws Exception {
Path existingPath = temporaryFolder.newFile().toPath();
Path nonExistentPath = existingPath.resolveSibling("non-existent");
Path destPath1 = existingPath.resolveSibling("dest1");
Path destPath2 = nonExistentPath.resolveSibling("dest2");
createFileWithContent(existingPath, "content1");
thrown.expect(NoSuchFileException.class);
FileSystems.copy(
toResourceIds(ImmutableList.of(existingPath, nonExistentPath), false /* isDirectory */),
toResourceIds(ImmutableList.of(destPath1, destPath2), false /* isDirectory */));
}
内容来源于网络,如有侵权,请联系作者删除!