@@ -0,0 +1,2876 @@
+/**%0A * Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A *%0A * This file is licensed under the Apache License, Version 2.0 (the %22License%22).%0A * You may not use this file except in compliance with the License. A copy of%0A * the License is located at%0A *%0A * http://aws.amazon.com/apache2.0/%0A *%0A * This file is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR%0A * CONDITIONS OF ANY KIND, either express or implied. See the License for the%0A * specific language governing permissions and limitations under the License.%0A *%0A */%0A%0A// snippet-comment:%5BThese are tags for the AWS doc team's sample catalog. Do not remove.%5D%0A// snippet-sourcedescription:%5BGetObjectTags.java demonstrates how to read tags that belong to an object located in an S3 bucket%5D%0A// snippet-service:%5BS3%5D%0A// snippet-keyword:%5BSDK for Java 2.0%5D%0A// snippet-keyword:%5BAmazon S3%5D%0A// snippet-keyword:%5BCode Sample%5D%0A// snippet-sourcetype:%5Bfull-example%5D%0A// snippet-sourcedate:%5B2020-01-09%5D%0A// snippet-sourceauthor:%5BAWS-scmacdon%5D%0A%0A// snippet-start:%5Bs3.java2.getobjecttags.complete%5D%0A%0Apackage com.example.s3;%0A%0A// snippet-start:%5Bs3.java2.getobjecttags.import%5D%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.s3.S3Client;%0Aimport software.amazon.awssdk.services.s3.model.*;%0A%0Aimport java.util.Iterator;%0Aimport java.util.List;%0A// snippet-end:%5Bs3.java2.getobjecttags.import%5D%0A%0A%0Apublic class GetObjectTags %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        if (args.length %3C 2) %7B%0A            System.out.println(%22Please specify a bucket name and key name%22);%0A            System.exit(1);%0A        %7D%0A%0A        // snippet-start:%5Bs3.java2.getobjecttags.main%5D%0A        String bucketName = args%5B0%5D;%0A        String keyName = args%5B1%5D;%0A%0A        try %7B%0A            Region region = Region.US_WEST_2;%0A            S3Client s3 = S3Client.builder().region(region).build();%0A%0A            // create a GetObjectTaggingRequest instance%0A            GetObjectTaggingRequest  getTaggingRequest = GetObjectTaggingRequest%0A                    .builder()%0A                    .key(keyName)%0A                    .bucket(bucketName)%0A                    .build();%0A%0A            // get the tags for this AWS S3 object%0A            GetObjectTaggingResponse tags = s3.getObjectTagging(getTaggingRequest);%0A            List%3CTag%3E tagSet= tags.tagSet();%0A%0A            // write out the tags%0A            Iterator%3CTag%3E tagIterator = tagSet.iterator();%0A            while(tagIterator.hasNext()) %7B%0A%0A                Tag tag = (Tag)tagIterator.next();%0A%0A                System.out.println(tag.key());%0A                System.out.println(tag.value());%0A            %7D%0A        %7D%0A        catch (S3Exception e) %7B%0A            System.err.println(e.awsErrorDetails().errorMessage());%0A            System.exit(1);%0A        %7D%0A        // snippet-end:%5Bs3.java2.getobjecttags.main%5D%0A    %7D%0A%7D%0A%0A// snippet-end:%5Bs3.java2.getobjecttags.complete%5D%0A

Create GetObjectTags.java