All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.markosindustries.distroboy.aws.s3.StreamToS3 Maven / Gradle / Ivy

The newest version!
package com.markosindustries.distroboy.aws.s3;

import com.markosindustries.distroboy.core.operations.ForEachOp;
import java.util.function.Function;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;

public class StreamToS3 implements ForEachOp {
  private final S3Client s3Client;
  private final String bucket;
  private final Function keyAccessor;
  private final Function requestBodyAccessor;

  public StreamToS3(
      S3Client s3Client,
      String bucket,
      Function keyAccessor,
      Function requestBodyAccessor) {
    this.s3Client = s3Client;
    this.bucket = bucket;
    this.keyAccessor = keyAccessor;
    this.requestBodyAccessor = requestBodyAccessor;
  }

  @Override
  public void forEach(I input) {
    String key = keyAccessor.apply(input);
    RequestBody requestBody = requestBodyAccessor.apply(input);
    s3Client.putObject(req -> req.bucket(bucket).key(key), requestBody);
  }
}