use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk by reactiverse.
the class VertxS3ClientSpec method createS3Bucket.
@Test
@Order(1)
@Timeout(value = 60, timeUnit = TimeUnit.SECONDS)
void createS3Bucket(Vertx vertx, VertxTestContext ctx) throws Exception {
final Context originalContext = vertx.getOrCreateContext();
final S3AsyncClient s3 = s3(originalContext);
single(s3.createBucket(VertxS3ClientSpec::createBucketReq)).subscribe(createRes -> {
assertContext(vertx, originalContext, ctx);
ctx.completeNow();
}, ctx::failNow);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk by reactiverse.
the class VertxS3ClientSpec method downloadImageFromBucketWithoutSettingResponseHandler.
@Test
@Order(7)
void downloadImageFromBucketWithoutSettingResponseHandler(Vertx vertx, VertxTestContext ctx) throws Exception {
final Context originalContext = vertx.getOrCreateContext();
final S3AsyncClient s3 = s3(originalContext);
final Buffer received = Buffer.buffer();
AtomicBoolean handlerCalled = new AtomicBoolean(false);
VertxAsyncResponseTransformer<GetObjectResponse> transformer = new VertxAsyncResponseTransformer<>(new WriteStream<Buffer>() {
@Override
public WriteStream<Buffer> exceptionHandler(Handler<Throwable> handler) {
return null;
}
@Override
public Future<Void> write(Buffer data) {
received.appendBuffer(data);
return Future.succeededFuture();
}
@Override
public void write(Buffer data, Handler<AsyncResult<Void>> handler) {
received.appendBuffer(data);
handler.handle(null);
}
@Override
public void end(Handler<AsyncResult<Void>> handler) {
assertTrue(handlerCalled.get(), "Response handler should have been called before first bytes are received");
if (received.length() == fileSize)
ctx.completeNow();
handler.handle(null);
}
@Override
public WriteStream<Buffer> setWriteQueueMaxSize(int maxSize) {
return null;
}
@Override
public boolean writeQueueFull() {
return false;
}
@Override
public WriteStream<Buffer> drainHandler(@Nullable Handler<Void> handler) {
return null;
}
});
transformer.setResponseHandler(resp -> {
handlerCalled.set(true);
});
single(s3.getObject(VertxS3ClientSpec::downloadImgReq, transformer)).subscribe(getRes -> ctx.completeNow(), ctx::failNow);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-sdk by reactiverse.
the class VertxS3ClientSpec method listObjectsV2.
@Test
@Order(8)
void listObjectsV2(Vertx vertx, VertxTestContext ctx) throws Exception {
final Context originalContext = vertx.getOrCreateContext();
final S3AsyncClient s3 = s3(originalContext);
single(s3.putObject(b -> putObjectReq(b, "obj1"), AsyncRequestBody.fromString("hello"))).flatMap(putObjectResponse1 -> single(s3.putObject(b -> putObjectReq(b, "obj2"), AsyncRequestBody.fromString("hi")))).flatMap(putObjectResponse2 -> single(s3.listObjectsV2(VertxS3ClientSpec::listObjectsV2Req)).flatMap(listObjectsV2Response1 -> single(s3.listObjectsV2(b -> listObjectsV2ReqWithContToken(b, listObjectsV2Response1.nextContinuationToken()))).map(listObjectsV2Response2 -> {
List<S3Object> allObjects = new ArrayList<>(listObjectsV2Response1.contents());
allObjects.addAll(listObjectsV2Response2.contents());
return allObjects;
}))).subscribe(allObjects -> {
ctx.verify(() -> {
assertEquals(3, allObjects.size());
ctx.completeNow();
});
}, ctx::failNow);
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project aws-doc-sdk-examples by awsdocs.
the class S3AsyncStreamOps method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " S3AsyncStreamOps <bucketName> <objectKey> <path>\n\n" + "Where:\n" + " bucketName - the name of the Amazon S3 bucket (for example, bucket1). \n\n" + " objectKey - the name of the object (for example, book.pdf). \n" + " path - the local path to the file (for example, C:/AWS/book.pdf). \n";
if (args.length != 3) {
System.out.println(USAGE);
System.exit(1);
}
String bucketName = args[0];
String objectKey = args[1];
String path = args[2];
Region region = Region.US_WEST_2;
S3AsyncClient client = S3AsyncClient.builder().region(region).build();
GetObjectRequest objectRequest = GetObjectRequest.builder().bucket(bucketName).key(objectKey).build();
CompletableFuture<GetObjectResponse> futureGet = client.getObject(objectRequest, AsyncResponseTransformer.toFile(Paths.get(path)));
futureGet.whenComplete((resp, err) -> {
try {
if (resp != null) {
System.out.println("Object downloaded. Details: " + resp);
} else {
err.printStackTrace();
}
} finally {
// Only close the client when you are completely done with it
client.close();
}
});
futureGet.join();
}
use of software.amazon.awssdk.services.s3.S3AsyncClient in project flink by apache.
the class KinesisFirehoseTableITTest method readFromS3.
private List<Order> readFromS3() throws Exception {
Deadline deadline = Deadline.fromNow(Duration.ofMinutes(1));
List<S3Object> ordersObjects;
List<Order> orders;
do {
Thread.sleep(1000);
ordersObjects = listBucketObjects(s3AsyncClient, BUCKET_NAME);
orders = readObjectsFromS3Bucket(s3AsyncClient, ordersObjects, BUCKET_NAME, responseBytes -> fromJson(new String(responseBytes.asByteArrayUnsafe()), Order.class));
} while (deadline.hasTimeLeft() && orders.size() < NUM_ELEMENTS);
return orders;
}
Aggregations