//snippet-sourcedescription:[S3AsyncOps.java demonstrates how to use the S3 asynchronous client to put an object into an Amazon S3 bucket]
//snippet-keyword:[SDK for Java 2.0]
//snippet-keyword:[Code Sample]
//snippet-service:[Amazon S3]
//snippet-sourcetype:[full-example]
//snippet-sourcedate:[2/6/2020]
//snippet-sourceauthor:[scmacdon-aws]

/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *    http://aws.amazon.com/apache2.0
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and
 * limitations under the License.
 */
package com.example.s3;
// snippet-start:[s3.java2.async_ops.complete]

// snippet-start:[s3.java2.async_ops.import]
import software.amazon.awssdk.core.async.AsyncRequestBody;
import software.amazon.awssdk.services.s3.S3AsyncClient;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
import java.nio.file.Paths;
import java.util.concurrent.CompletableFuture;
// snippet-end:[s3.java2.async_ops.import]

public class S3AsyncOps {

       public static void main(String[] args) {

           final String USAGE = "\n" +
                   "Usage:\n" +
                   "    S3AsyncOps <bucketname> <objectname> <path>\n\n" +
                   "Where:\n" +
                   "    bucketname - the name of the bucket (i.e., bucket1)\n\n" +
                   "    objectname - the name pf the object object (i.e., book.pdf)\n" +
                   "    path - the local path to the file (i.e., C:\\AWS\\book.pdf)\n" +
                   "Example:\n" +
                   "    bucket1 book.pdf  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];

           // Create a S3AsyncClient object
           S3AsyncClient client = S3AsyncClient.create();
           S3AsyncOperations( client, bucketName,  objectKey , path );
       }

    // snippet-start:[s3.java2.async_ops.main]
       public static void  S3AsyncOperations( S3AsyncClient client,  String bucketName,  String objectKey ,String path  ) {

        CompletableFuture<PutObjectResponse> future = client.putObject(
                PutObjectRequest.builder()
                        .bucket(bucketName)
                        .key(objectKey)
                        .build(),
                AsyncRequestBody.fromFile(Paths.get(path))
        );
        future.whenComplete((resp, err) -> {
            try {
                if (resp != null) {
                    System.out.println("my response: " + resp);
                } else {
                    // Handle error
                    err.printStackTrace();
                }
            } finally {
                // Lets the application shut down. Only close the client when you are completely done with it.
                client.close();
            }
        });

        future.join();
    }
}
// snippet-end:[s3.java2.async_ops.main]
// snippet-end:[s3.java2.async_ops.complete]

@@ -92,50 +92,9 @@
 ient
- to put an object into an Amazon S3 bucket
+.
 %5D%0D%0A/
@@ -186,16 +186,9 @@
 ce:%5B
-Amazon S
+s
 3%5D%0D%0A
@@ -250,16 +250,8 @@
 te:%5B
-2/6/2020
 %5D%0D%0A/
@@ -278,24 +278,17 @@
 r:%5Bs
-cmacdon
+oo
 -aws%5D%0D%0A
-%0D%0A
 /*%0D%0A
@@ -300,16 +300,26 @@
 pyright 
+2011-2019 
 Amazon.c
@@ -913,18 +913,16 @@
 plete%5D%0D%0A
-%0D%0A
 // snipp
@@ -959,16 +959,18 @@
 mport%5D%0D%0A
+%0D%0A
 import s
@@ -1214,16 +1214,72 @@
 ponse;%0D%0A
+import software.amazon.awssdk.utils.FunctionalUtils;%0D%0A%0D%0A
 import j
@@ -1395,1243 +1395,287 @@
 t%5D%0D%0A
-%0D%0Apublic class S3AsyncOps %7B%0D%0A%0D%0A       public static void main(String%5B%5D args) %7B%0D%0A%0D%0A           final String USAGE = %22%5Cn%22 +%0D%0A                   %22Usage:%5Cn%22 +%0D%0A                   %22    S3AsyncOps %3Cbucketname%3E %3Cobjectname%3E %3Cpath%3E%5Cn%5Cn%22 +%0D%0A                   %22Where:%5Cn%22 +%0D%0A                   %22    bucketname - the name of the bucket (i.e., bucket1)%5Cn%5Cn%22 +%0D%0A                   %22    objectname - the name pf the object object (i.e., book.pdf)%5Cn%22 +%0D%0A                   %22    path - the local path to the file (i.e., C:%5C%5CAWS%5C%5Cbook.pdf)%5Cn%22 +%0D%0A                   %22Example:%5Cn%22 +%0D%0A                   %22    bucket1 book.pdf  C:%5C%5CAWS%5C%5Cbook.pdf%5Cn%22;%0D%0A%0D%0A           if (args.length %3C 3) %7B%0D%0A               System.out.println(USAGE);%0D%0A               System.exit(1);%0D%0A           %7D%0D%0A%0D%0A           String bucketName = args%5B0%5D;%0D%0A           String objectKey = args%5B1%5D;%0D%0A           String path = args%5B2%5D;%0D%0A%0D%0A           // Create a S3AsyncClient object%0D%0A           S3AsyncClient client = S3AsyncClient.create();%0D%0A           S3AsyncOperations( client, bucketName,  objectKey , path );%0D%0A       %7D%0D%0A%0D%0A    // snippet-start:%5Bs3.java2.async_ops.main%5D%0D%0A       public static void  S3AsyncOperations( S3AsyncClient client,  String bucketName,  String objectKey ,String path  ) %7B%0D%0A
+// snippet-start:%5Bs3.java2.async_ops.main%5D%0D%0Apublic class S3AsyncOps %7B%0D%0A%0D%0A    private static final String BUCKET = %22sample-bucket%22;%0D%0A%09private static final String KEY = %22testfile.in%22;%0D%0A%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A    %09S3AsyncClient client = S3AsyncClient.create();
 %0D%0A  
@@ -1817,29 +1817,37 @@
     
-.bucket(bucketName)%0D%0A
+        .bucket(BUCKET)%0D%0A    
     
@@ -1870,25 +1870,31 @@
     
+    
 .key(
-objectKey)%0D%0A
+KEY)%0D%0A        
     
@@ -1980,12 +1980,19 @@
 get(
-path
+%22myfile.in%22
 ))%0D%0A
@@ -2530,16 +2530,19 @@
   %7D%0D%0A%7D%0D%0A
+ %0D%0A
 // snipp

Update S3AsyncOps.java