use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.hash.HashCode in project beam by apache.
the class PackageUtilTest method makeStagedFile.
private static StagedFile makeStagedFile(String source, String destName) throws IOException {
File file = new File(source);
File sourceFile;
HashCode hashCode;
if (file.exists()) {
sourceFile = file.isDirectory() ? zipDirectory(file) : file;
hashCode = Files.asByteSource(sourceFile).hash(Hashing.sha256());
} else {
sourceFile = file;
hashCode = Hashing.sha256().hashBytes(new byte[] {});
}
String destination = destName == null ? Environments.createStagingFileName(file, hashCode) : destName;
return StagedFile.of(sourceFile.getPath(), hashCode.toString(), destination);
}
use of org.apache.beam.vendor.guava.v26_0_jre.com.google.common.hash.HashCode in project beam by apache.
the class GCSUploadMain method main.
public static void main(String[] args) {
DataflowPipelineOptions options = PipelineOptionsFactory.fromArgs(args).as(DataflowPipelineOptions.class);
FileSystems.setDefaultPipelineOptions(options);
GcsStager stager = GcsStager.fromOptions(options);
stager.stageFiles(options.getFilesToStage().stream().map((String source) -> {
try {
File file = new File(source);
HashCode hashCode = Files.asByteSource(file).hash(Hashing.sha256());
return PackageUtil.StagedFile.of(source, hashCode.toString(), Environments.createStagingFileName(file, hashCode));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).collect(Collectors.toList()));
}
Aggregations