use of software.amazon.awssdk.core.ResponseInputStream in project flyway by flyway.
the class AwsS3Resource method read.
@Override
public Reader read() {
S3Client s3 = S3ClientFactory.getClient();
try {
GetObjectRequest.Builder builder = GetObjectRequest.builder().bucket(bucketName).key(s3ObjectSummary.key());
GetObjectRequest request = builder.build();
ResponseInputStream o = s3.getObject(request);
return Channels.newReader(Channels.newChannel(o), encoding.name());
} catch (AwsServiceException e) {
LOG.error(e.getMessage(), e);
throw new FlywayException("Failed to get object from s3: " + e.getMessage(), e);
}
}
use of software.amazon.awssdk.core.ResponseInputStream in project hazelcast by hazelcast.
the class S3Sources method s3.
/**
* Creates an AWS S3 {@link BatchSource} which lists all the objects in the
* bucket-list using given {@code prefix}, reads them line by line,
* transforms each line to the desired output object using given {@code
* mapFn} and emits them to downstream.
* <p>
* The source does not save any state to snapshot. If the job is restarted,
* it will re-emit all entries.
* <p>
* The default local parallelism for this processor is 2.
* <p>
* Here is an example which reads the objects from a single bucket with
* applying the given prefix.
*
* <pre>{@code
* Pipeline p = Pipeline.create();
* BatchStage<String> srcStage = p.readFrom(S3Sources.s3(
* Arrays.asList("bucket1", "bucket2"),
* "prefix",
* StandardCharsets.UTF_8,
* () -> S3Client.create(),
* (filename, line) -> line
* ));
* }</pre>
*
* @param bucketNames list of bucket-names
* @param prefix the prefix to filter the objects. Optional, passing
* {@code null} will list all objects.
* @param clientSupplier function which returns the s3 client to use
* one client per processor instance is used
* @param mapFn the function which creates output object from each
* line. Gets the object name and line as parameters
* @param <T> the type of the items the source emits
*/
@Nonnull
public static <T> BatchSource<T> s3(@Nonnull List<String> bucketNames, @Nullable String prefix, @Nonnull Charset charset, @Nonnull SupplierEx<? extends S3Client> clientSupplier, @Nonnull BiFunctionEx<String, String, ? extends T> mapFn) {
String charsetName = charset.name();
FunctionEx<InputStream, Stream<String>> readFileFn = responseInputStream -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(responseInputStream, Charset.forName(charsetName)));
return reader.lines();
};
return s3(bucketNames, prefix, clientSupplier, readFileFn, mapFn);
}
Aggregations