use of com.amazonaws.services.s3.model.S3ObjectSummary in project XRTB by benmfaul.
the class Configuration method processDirectory.
public void processDirectory(AmazonS3Client s3, ObjectListing listing, String bucket) throws Exception {
for (S3ObjectSummary objectSummary : listing.getObjectSummaries()) {
long size = objectSummary.getSize();
System.out.println("*** Processing S3 " + objectSummary.getKey() + ", size = " + size);
S3Object object = s3.getObject(new GetObjectRequest(bucket, objectSummary.getKey()));
String bucketName = object.getBucketName();
String keyName = object.getKey();
if (keyName.contains("Darren")) {
System.out.println("HERE");
}
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);
}
}
}
use of com.amazonaws.services.s3.model.S3ObjectSummary in project aws-doc-sdk-examples by awsdocs.
the class ListObjects method main.
public static void main(String[] args) {
final String USAGE = "\n" + "To run this example, supply the name of a bucket to list!\n" + "\n" + "Ex: ListObjects <bucket-name>\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
System.out.format("Objects in S3 bucket %s:\n", bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
ObjectListing ol = s3.listObjects(bucket_name);
List<S3ObjectSummary> objects = ol.getObjectSummaries();
for (S3ObjectSummary os : objects) {
System.out.println("* " + os.getKey());
}
}
use of com.amazonaws.services.s3.model.S3ObjectSummary in project aws-doc-sdk-examples by awsdocs.
the class DeleteBucket method main.
public static void main(String[] args) {
final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket\n" + "\n" + "Ex: DeleteBucket <bucketname>\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
System.out.println("Deleting S3 bucket: " + bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
System.out.println(" - removing objects from bucket");
ObjectListing object_listing = s3.listObjects(bucket_name);
while (true) {
for (Iterator<?> iterator = object_listing.getObjectSummaries().iterator(); iterator.hasNext(); ) {
S3ObjectSummary summary = (S3ObjectSummary) iterator.next();
s3.deleteObject(bucket_name, summary.getKey());
}
// more object_listing to retrieve?
if (object_listing.isTruncated()) {
object_listing = s3.listNextBatchOfObjects(object_listing);
} else {
break;
}
}
;
System.out.println(" - removing versions from bucket");
VersionListing version_listing = s3.listVersions(new ListVersionsRequest().withBucketName(bucket_name));
while (true) {
for (Iterator<?> iterator = version_listing.getVersionSummaries().iterator(); iterator.hasNext(); ) {
S3VersionSummary vs = (S3VersionSummary) iterator.next();
s3.deleteVersion(bucket_name, vs.getKey(), vs.getVersionId());
}
if (version_listing.isTruncated()) {
version_listing = s3.listNextBatchOfVersions(version_listing);
} else {
break;
}
}
System.out.println(" OK, bucket ready to delete!");
s3.deleteBucket(bucket_name);
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.services.s3.model.S3ObjectSummary in project zeppelin by apache.
the class S3NotebookRepo method remove.
@Override
public void remove(String noteId, AuthenticationInfo subject) throws IOException {
String key = user + "/" + "notebook" + "/" + noteId;
final ListObjectsRequest listObjectsRequest = new ListObjectsRequest().withBucketName(bucketName).withPrefix(key);
try {
ObjectListing objects = s3client.listObjects(listObjectsRequest);
do {
for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) {
s3client.deleteObject(bucketName, objectSummary.getKey());
}
objects = s3client.listNextBatchOfObjects(objects);
} while (objects.isTruncated());
} catch (AmazonClientException ace) {
throw new IOException("Unable to remove note in S3: " + ace, ace);
}
}
use of com.amazonaws.services.s3.model.S3ObjectSummary in project YCSB by brianfrankcooper.
the class S3Client method scanFromStorage.
/**
* Perform an emulation of a database scan operation on a S3 bucket.
*
* @param bucket
* The name of the bucket
* @param startkey
* The file key of the first file to read.
* @param recordcount
* The number of files to read
* @param fields
* The list of fields to read, or null for all of them
* @param result
* A Vector of HashMaps, where each HashMap is a set field/value
* pairs for one file
*
*/
protected Status scanFromStorage(String bucket, String startkey, int recordcount, Vector<HashMap<String, ByteIterator>> result, SSECustomerKey ssecLocal) {
int counter = 0;
ObjectListing listing = s3Client.listObjects(bucket);
List<S3ObjectSummary> summaries = listing.getObjectSummaries();
List<String> keyList = new ArrayList();
int startkeyNumber = 0;
int numberOfIteration = 0;
// getting the list of files in the bucket
while (listing.isTruncated()) {
listing = s3Client.listNextBatchOfObjects(listing);
summaries.addAll(listing.getObjectSummaries());
}
for (S3ObjectSummary summary : summaries) {
String summaryKey = summary.getKey();
keyList.add(summaryKey);
}
// Sorting the list of files in Alphabetical order
// sorting the list
Collections.sort(keyList);
// Getting the position of the startingfile for the scan
for (String key : keyList) {
if (key.equals(startkey)) {
startkeyNumber = counter;
} else {
counter = counter + 1;
}
}
// if not using the total number of Files
if (recordcount < keyList.size()) {
numberOfIteration = recordcount;
} else {
numberOfIteration = keyList.size();
}
// of the Files or Till the recordcount number
for (int i = startkeyNumber; i < numberOfIteration; i++) {
HashMap<String, ByteIterator> resultTemp = new HashMap<String, ByteIterator>();
readFromStorage(bucket, keyList.get(i), resultTemp, ssecLocal);
result.add(resultTemp);
}
return Status.OK;
}
Aggregations