本文整理了Java中org.apache.beam.sdk.io.FileSystems.rename()
方法的一些代码示例,展示了FileSystems.rename()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileSystems.rename()
方法的具体详情如下:
包路径:org.apache.beam.sdk.io.FileSystems
类名称:FileSystems
方法名:rename
[英]Renames 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 renaming globs.
[中]将类似文件的资源列表从一个位置重命名到另一个位置。
源资源的数量必须等于目标资源的数量。目标资源将以递归方式创建。
SrcResourceId和DestresourceId必须具有相同的方案。
它不支持重命名全局。
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
FileSystems.rename(srcFiles, dstFiles, StandardMoveOptions.IGNORE_MISSING_FILES);
removeTemporaryFiles(srcFiles);
代码示例来源:origin: GoogleCloudPlatform/DataflowTemplates
FileSystems.rename(
ImmutableList.of(tempFile),
ImmutableList.of(outputFile),
代码示例来源:origin: GoogleCloudPlatform/DataflowTemplates
@ProcessElement
public void processElement(ProcessContext context) {
ResourceId inputFile = context.element().resourceId();
Compression compression = compressionValue.get();
// Add the compression extension to the output filename. Example: demo.txt -> demo.txt.gz
String outputFilename = inputFile.getFilename() + compression.getSuggestedSuffix();
// Resolve the necessary resources to perform the transfer
ResourceId outputDir = FileSystems.matchNewResource(destinationLocation.get(), true);
ResourceId outputFile =
outputDir.resolve(outputFilename, StandardResolveOptions.RESOLVE_FILE);
ResourceId tempFile =
outputDir.resolve("temp-" + outputFilename, StandardResolveOptions.RESOLVE_FILE);
// Perform the copy of the compressed channel to the destination.
try (ReadableByteChannel readerChannel = FileSystems.open(inputFile)) {
try (WritableByteChannel writerChannel =
compression.writeCompressed(FileSystems.create(tempFile, MimeTypes.BINARY))) {
// Execute the copy to the temporary file
ByteStreams.copy(readerChannel, writerChannel);
}
// Rename the temporary file to the output file
FileSystems.rename(ImmutableList.of(tempFile), ImmutableList.of(outputFile));
// Output the path to the uncompressed file
context.output(outputFile.toString());
} catch (IOException e) {
LOG.error("Error occurred during compression of {}", inputFile.toString(), e);
context.output(DEADLETTER_TAG, KV.of(inputFile.toString(), e.getMessage()));
}
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@Test
public void testRenameIgnoreMissingFiles() 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.rename(
toResourceIds(
ImmutableList.of(srcPath1, nonExistentPath, srcPath3), false /* isDirectory */),
toResourceIds(ImmutableList.of(destPath1, destPath2, destPath3), false /* isDirectory */),
MoveOptions.StandardMoveOptions.IGNORE_MISSING_FILES);
assertFalse(srcPath1.toFile().exists());
assertFalse(srcPath3.toFile().exists());
assertThat(
Files.readLines(destPath1.toFile(), StandardCharsets.UTF_8),
containsInAnyOrder("content1"));
assertFalse(destPath2.toFile().exists());
assertThat(
Files.readLines(destPath3.toFile(), StandardCharsets.UTF_8),
containsInAnyOrder("content3"));
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@Test
public void testRenameThrowsNoSuchFileException() 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.rename(
toResourceIds(ImmutableList.of(existingPath, nonExistentPath), false /* isDirectory */),
toResourceIds(ImmutableList.of(destPath1, destPath2), false /* isDirectory */));
}
内容来源于网络,如有侵权,请联系作者删除!