Java Code Examples for com.amazonaws.services.s3.model.S3Object#getBucketName()

The following examples show how to use com.amazonaws.services.s3.model.S3Object#getBucketName() . 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: SimpleSet.java    From bidder with Apache License 2.0 5 votes vote down vote up
/**
 * A simple set. Reads S3 object and put into the Set.
 * @param name String. The name of the object.
 * @param object S3Object. The S3 object to read.
 * @throws Exception on S3 or I/O options.
 */
public SimpleSet(String name, S3Object object) throws Exception {
	InputStream objectData = object.getObjectContent();
	BufferedReader br=new BufferedReader(new InputStreamReader(objectData));
	message = "Initialize Simple Membership: " + object.getBucketName() + " as " + name;
	makeSet(br);
	
	symbols.put(name, this);
}
 
Example 2
Source File: ProportionalRandomCollection.java    From bidder with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the S3 version of the ProportionalRandomCollection.
 *
 * @param name   String. The name of the object.
 * @param object S3Object. The object that contains the file.
 * @throws Exception on S3 errors.
 */
public ProportionalRandomCollection(String name, S3Object object) throws Exception {
    InputStream objectData = object.getObjectContent();
    String message = "Initialize ProportionalRandomCollection: " + object.getBucketName() + " as " + name;
    BufferedReader br = new BufferedReader(new InputStreamReader(objectData));
    makeFilter(br);
    symbols.put(name, this);
    logger.info("{}", message);
}
 
Example 3
Source File: NavMap.java    From bidder with Apache License 2.0 5 votes vote down vote up
/**
 * A navigable hashmap for handling CIDR lists and range maps from an S3
 * object.
 * 
 * @param name
 *            String. The name of the object.
 * @param object
 *            S3Object. The S3 object for this..
 * @throws Exception
 *             on I/O errors.
 */
public NavMap(String name, S3Object object, String type) throws Exception {
	this.name = name;
	String file = object.getBucketName();
	InputStream objectData = object.getObjectContent();
	BufferedReader br = new BufferedReader(new InputStreamReader(objectData));
	if (type.equalsIgnoreCase("cidr")) {
		doCidr(br);
	} else if (type.equalsIgnoreCase("range")) {
		doRanges(br);
	} else
		throw new Exception(file + " Not in range or CIDR form");
	
	symbols.put(name, this);
}
 
Example 4
Source File: SimpleSet.java    From XRTB with Apache License 2.0 5 votes vote down vote up
/**
 * A simple set. Reads S3 object and put into the Set.
 * @param name String. The name of the object.
 * @param object S3Object. The S3 object to read.
 * @throws Exception on S3 or I/O options.
 */
public SimpleSet(String name, S3Object object) throws Exception {
	InputStream objectData = object.getObjectContent();
	BufferedReader br=new BufferedReader(new InputStreamReader(objectData));
	message = "Initialize Simple Membership: " + object.getBucketName() + " as " + name;
	makeSet(br);
	
	symbols.put(name, this);
}
 
Example 5
Source File: NavMap.java    From XRTB with Apache License 2.0 5 votes vote down vote up
/**
 * A navigable hashmap for handling CIDR lists and range maps from an S3
 * object.
 * 
 * @param name
 *            String. The name of the object.
 * @param object
 *            S3Object. The S3 object for this..
 * @throws Exception
 *             on I/O errors.
 */
public NavMap(String name, S3Object object) throws Exception {
	this.name = name;
	String file = object.getBucketName();
	InputStream objectData = object.getObjectContent();
	BufferedReader br = new BufferedReader(new InputStreamReader(objectData));
	if (file.endsWith("cidr")) {
		doCidr(br, file);
	} else if (file.endsWith("range")) {
		doRanges(br, file);
	} else
		throw new Exception(file + " Not in range or CIDR form");
}
 
Example 6
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 7
Source File: Configuration.java    From XRTB with Apache License 2.0 4 votes vote down vote up
public void processDirectory(AmazonS3Client s3, ObjectListing listing, String bucket) throws Exception {
	for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
		long size = objectSummary.getSize();
		logger.info("*** 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()) {
			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;

			readData(type, name, object, size);
		}
	}
}
 
Example 8
Source File: AmazonS3FileSystem.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public String getCanonicalName(S3Object f) throws FileSystemException {
	return f.getBucketName() + f.getKey();
}