Java 从 HDFS 传输到 S3

标签 java amazon-s3 hdfs

我想用 Java 将文件从 HDFS 传输到 S3。有些文件可能很大,所以我不想在将文件上传到 S3 之前将其下载到本地。在 Java 中有什么方法可以做到这一点吗?

这是我现在拥有的(一段将本地文件上传到 S3 的代码)。我不能真正使用它,因为使用 File 对象意味着我将它放在我的硬盘上。

File f = new File("/home/myuser/test");

TransferManager transferManager  = new TransferManager(credentials);
MultipleFileUpload upload = transferManager.uploadDirectory("mybucket","test_folder",f,true);

谢谢

最佳答案

我弄清楚了上传部分。

AWSCredentials credentials = new BasicAWSCredentials(
            "whatever",
            "whatever");

    File f = new File("/home/myuser/test");

    TransferManager transferManager  = new TransferManager(credentials);

    //+upload from HDFS to S3
    Configuration conf = new Configuration();
    // set the hadoop config files
    conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
    conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));

    Path path = new Path("hdfs://my_ip_address/user/ubuntu/test/test.txt");
    FileSystem fs = path.getFileSystem(conf);
    FSDataInputStream inputStream = fs.open(path);
    ObjectMetadata objectMetadata =  new ObjectMetadata();
    Upload upload = transferManager.upload("xpatterns-deployment-ubuntu", "test_cu_jmen3", inputStream, objectMetadata);
    //-upload from HDFS to S3

    try {
        upload.waitForCompletion();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

关于如何为下载做类似的事情有什么想法吗?我还没有在 TransferManager 中找到任何可以使用上述代码中的流的 download() 方法。

关于Java 从 HDFS 传输到 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31877386/

相关文章:

hadoop - 如何直接从网页下载文件,不使用本地,直接将文件放在HDFS中?

java - 是否可以在另一个方法 "AsyncTask"中运行 "AsyncTask"方法?

java - 并行调用mysql数据库时的注意事项

java - 跟踪中提到的最顶行是否总是抛出空值?

node.js - 如何将保存到S3的文件推送到前端下载?

hadoop - HDFS NFS 启动错误 : “ERROR mount.MountdBase: Failed to start the TCP server...ChannelException: Failed to bind..."

java - Java中一个接口(interface)可以扩展多个接口(interface)吗?

postgresql - Heroku pg :backups:restore from public_url. 找不到备份。

amazon-web-services - 当 key 包含阿拉伯字符时,AWS Golang SDK 无法复制对象

hadoop - Hadoop 大数据中的复制因子