// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
// snippet-sourcedescription:[GetObjectTags.java demonstrates how to read tags that belong to an object located in an S3 bucket]
// snippet-service:[S3]
// snippet-keyword:[SDK for Java 2.0]
// snippet-keyword:[Amazon S3]
// snippet-keyword:[Code Sample]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[2020-01-09]
// snippet-sourceauthor:[AWS-scmacdon]

/**
 * Copyright 2010-2020 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.
 *
 */

// snippet-start:[s3.java2.getobjecttags.complete]

package com.example.s3;

// snippet-start:[s3.java2.getobjecttags.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectTaggingRequest;
import software.amazon.awssdk.services.s3.model.GetObjectTaggingResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.awssdk.services.s3.model.Tag;
import java.util.Iterator;
import java.util.List;
// snippet-end:[s3.java2.getobjecttags.import]

public class GetObjectTags {

    public static void main(String[] args) {

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

        // snippet-start:[s3.java2.getobjecttags.main]
        String bucketName = args[0];
        String keyName = args[1];

        try {
            Region region = Region.US_WEST_2;
            S3Client s3 = S3Client.builder().region(region).build();

            // create a GetObjectTaggingRequest instance
            GetObjectTaggingRequest getTaggingRequest = GetObjectTaggingRequest
                    .builder()
                    .key(keyName)
                    .bucket(bucketName)
                    .build();

            // get the tags for this AWS S3 object
            GetObjectTaggingResponse tags = s3.getObjectTagging(getTaggingRequest);
            List<Tag> tagSet= tags.tagSet();

            // write out the tags
            Iterator<Tag> tagIterator = tagSet.iterator();
            while(tagIterator.hasNext()) {

                Tag tag = (Tag)tagIterator.next();

                System.out.println(tag.key());
                System.out.println(tag.value());
            }
        } catch (S3Exception e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        // snippet-end:[s3.java2.getobjecttags.main]
    }
}
// snippet-end:[s3.java2.getobjecttags.complete]

@@ -201,16 +201,23 @@
 d in an 
+Amazon 
 S3 bucke
@@ -239,16 +239,23 @@
 ervice:%5B
+Amazon 
 S3%5D%0A// s
@@ -383,33 +383,32 @@
 full-example%5D%0A//
- 
 snippet-sourceda
@@ -416,22 +416,19 @@
 e:%5B2
-020-01-09
+/6/2020
 %5D%0A//
- 
 snip
@@ -449,20 +449,16 @@
 or:%5B
-AWS-
 scmacdon
 %5D%0A%0A/
@@ -453,16 +453,20 @@
 scmacdon
+-aws
 %5D%0A%0A/**%0A 
@@ -481,18 +481,8 @@
 ght 
-2010-2020 
 Amaz
@@ -1004,61 +1004,8 @@
  */%0A
-%0A// snippet-start:%5Bs3.java2.getobjecttags.complete%5D%0A%0A
 pack
@@ -1615,16 +1615,17 @@
         
+ 
 if (args
@@ -1635,24 +1635,26 @@
 ngth %3C 2) %7B%0A
+  
             
@@ -1722,32 +1722,34 @@
 %22);%0A            
+  
 System.exit(1);%0A
@@ -1760,65 +1760,12 @@
     
+  
 %7D%0A
-%0A        // snippet-start:%5Bs3.java2.getobjecttags.main%5D
 %0A   
@@ -1837,26 +1837,8 @@
 %5D;%0A%0A
-        try %7B%0A    
     
@@ -1883,20 +1883,16 @@
         
-    
 S3Client
@@ -1919,35 +1919,268 @@
 er()
-.region(region).build();%0A%0A 
+%0A                .region(region)%0A                .build();%0A%0A        ListTags(s3,bucketName,keyName );%0A    %7D%0A%0A    // snippet-start:%5Bs3.java2.getobjecttags.main%5D%0A    public static void ListTags (S3Client s3, String bucketName, String keyName ) %7B%0A%0A         try %7B%0A
     
@@ -2812,25 +2812,24 @@
 tor.next();%0A
-%0A
             
@@ -3131,53 +3131,4 @@
 %7D%0A%7D%0A
-// snippet-end:%5Bs3.java2.getobjecttags.complete%5D%0A

Update GetObjectTags.java