Java Code Examples for com.amazonaws.services.s3.AmazonS3#getObjectTagging()

The following examples show how to use com.amazonaws.services.s3.AmazonS3#getObjectTagging() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListAws.java    From bidder with Apache License 2.0 4 votes vote down vote up
public static void processDirectory(AmazonS3 s3, ObjectListing listing, String bucket) throws Exception {
    for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
        long size = objectSummary.getSize();
        S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));

        String bucketName = object.getBucketName();
        String keyName = object.getKey();

        GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucketName, keyName);
        GetObjectTaggingResult result = s3.getObjectTagging(request);
        List<Tag> tags = result.getTagSet();
        String type = null;
        String name = null;

        if (tags.isEmpty()) {
            System.err.println("Error: " + keyName + " has no tags");
        } else {
            for (Tag tag : tags) {
                String key = tag.getKey();
                String value = tag.getValue();

                if (key.equals("type")) {
                    type = value;
                }

                if (key.equals("name")) {
                    name = value;
                }
            }

            if (name == null)
                throw new Exception("Error: " + keyName + " is missing a name tag");
            if (name.contains(" "))
                throw new Exception("Error: " + keyName + " has a name attribute with a space in it");
            if (type == null)
                throw new Exception("Error: " + keyName + " has no type tag");

            if (!name.startsWith("$"))
                name = "$" + name;

            System.out.println("type: " + type + ", name: " + name + ", size: " + size);
        }
    }
}
 
Example 2
Source File: Configuration.java    From bidder with Apache License 2.0 4 votes vote down vote up
public void processDirectory(AmazonS3 s3, ObjectListing listing, String bucket) throws Exception {

		double time = System.currentTimeMillis();
		ExecutorService executor = Executors.newFixedThreadPool(16);

		int count = 0;

		for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
			if ("STANDARD".equalsIgnoreCase(objectSummary.getStorageClass())) {
				long size = objectSummary.getSize();
				logger.debug("*** Processing S3 {}, size: {}", objectSummary.getKey(), size);
				S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));

				String bucketName = object.getBucketName();
				String keyName = object.getKey();

				GetObjectTaggingRequest request = new GetObjectTaggingRequest(bucketName, keyName);
				GetObjectTaggingResult result = s3.getObjectTagging(request);
				List<Tag> tags = result.getTagSet();
				String type = null;
				String name = null;

				if (tags.isEmpty()) {
					object.close();
					logger.warn("Error, S3 object: {} has no tags", keyName);
				} else {
					for (Tag tag : tags) {
						String key = tag.getKey();
						String value = tag.getValue();

						if (key.equals("type")) {
							type = value;
						}

						if (key.equals("name")) {
							name = value;
						}
					}

					if (name == null) {
						object.close();
						throw new Exception("Error: " + keyName + " is missing a name tag");
					}
					if (name.contains(" ")) {
						object.close();
						throw new Exception("Error: " + keyName + " has a name attribute with a space in it");
					}
					if (type == null) {
						object.close();
						throw new Exception("Error: " + keyName + " has no type tag");
					}

					if (!name.startsWith("$"))
						name = "$" + name;

					// The runnable will call object.close();
					Runnable w = new AwsWorker(type, name, object, size);
					executor.execute(w);

					count++;
				}
			}
		}
		executor.shutdown();
		executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);

		time = System.currentTimeMillis() - time;
		time = time / 60000;
		logger.info("Initialized all {} S3 objects in {} minutes", count, time);
	}
 
Example 3
Source File: S3OperationsImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public GetObjectTaggingResult getObjectTagging(GetObjectTaggingRequest getObjectTaggingRequest, AmazonS3 s3Client)
{
    return s3Client.getObjectTagging(getObjectTaggingRequest);
}
 
Example 4
Source File: GetObjectTags2.java    From aws-doc-sdk-examples with Apache License 2.0 3 votes vote down vote up
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.java.getobjecttags.main]
        String bucketName = args[0];
        String keyName = args[1];

        System.out.println("Retrieving Object Tags for  " + keyName);

        final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();

        try {

            GetObjectTaggingRequest getTaggingRequest = new GetObjectTaggingRequest(bucketName, keyName);

            GetObjectTaggingResult tags = s3.getObjectTagging(getTaggingRequest);

            List<Tag> tagSet= tags.getTagSet();

            //Iterate through the list
            Iterator<Tag> tagIterator = tagSet.iterator();

            while(tagIterator.hasNext()) {

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

                System.out.println(tag.getKey());
                System.out.println(tag.getValue());
            }

        } catch (AmazonServiceException e) {
            System.err.println(e.getErrorMessage());
            System.exit(1);
        }
        // snippet-end:[s3.java.getobjecttags.main]
    }
 
Example 5
Source File: GetObjectTags.java    From aws-doc-sdk-examples with Apache License 2.0 3 votes vote down vote up
public static void main(String[] args) throws IOException {

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

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

        System.out.println("Retrieving Object Tags for  " + keyName);

        final AmazonS3 s3 = AmazonS3ClientBuilder.standard().withRegion(Regions.DEFAULT_REGION).build();

        try {

            GetObjectTaggingRequest getTaggingRequest = new GetObjectTaggingRequest(bucketName, keyName);

            GetObjectTaggingResult tags = s3.getObjectTagging(getTaggingRequest);

            List<Tag> tagSet= tags.getTagSet();

            //Iterate through the list
            Iterator<Tag> tagIterator = tagSet.iterator();

            while(tagIterator.hasNext()) {

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

                System.out.println(tag.getKey());
                System.out.println(tag.getValue());
            }

        } catch (AmazonServiceException e) {
            System.err.println(e.getErrorMessage());
            System.exit(1);
        }
        // snippet-end:[s3.java.getobjecttags.main]
    }