//snippet-sourcedescription:[ListObjects.java demonstrates how to list objects located in a given 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.
 *
 * This file is licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License. A copy of
 * the License is located 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.list_objects.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.model.S3Object;
import java.util.List;
import java.util.ListIterator;
// snippet-end:[s3.java2.list_objects.import]

public class ListObjects {

    public static void main(String[] args) {

        if (args.length < 1) {
           System.out.println("Please specify a bucket name");
           System.exit(1);
         }

        String bucketName = args[0];
        Region region = Region.US_WEST_2;
        S3Client s3 = S3Client.builder()
                .region(region)
                .build();

        ListBucketObjects(s3, bucketName);

    }

    // snippet-start:[s3.java2.list_objects.main]
    public static void ListBucketObjects(  S3Client s3, String bucketName ) {

       try {
            ListObjectsRequest listObjects = ListObjectsRequest
                    .builder()
                    .bucket(bucketName)
                    .build();

            ListObjectsResponse res = s3.listObjects(listObjects);
            List<S3Object> objects = res.contents();

            for (ListIterator iterVals = objects.listIterator(); iterVals.hasNext(); ) {
                S3Object myValue = (S3Object) iterVals.next();
                System.out.print("\n The name of the key is " + myValue.key());
                System.out.print("\n The object is " + calKb(myValue.size()) + " KBs");
                System.out.print("\n The owner is " + myValue.owner());
            }
        } catch (S3Exception e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
    }
    //convert bytes to kbs
    private static long calKb(Long val) {
        return val/1024;

    }
    // snippet-end:[s3.java2.list_objects.main]
}

@@ -1778,17 +1778,17 @@
         
-L
+l
 istBucke
@@ -1813,17 +1813,16 @@
 tName);%0A
-%0A
     %7D%0A%0A 
@@ -1893,17 +1893,17 @@
 ic void 
-L
+l
 istBucke
@@ -1911,18 +1911,16 @@
 Objects(
-  
 S3Client
@@ -2647,24 +2647,28 @@
             
+    
 %7D%0A        %7D 
@@ -2897,24 +2897,22 @@
 l/1024;%0A
-%0A
     %7D%0A
- 
    // sn

Update ListObjects.java