use of com.amazonaws.services.s3.AmazonS3 in project jackrabbit-oak by apache.
the class Utils method deleteBucket.
/**
* Delete S3 bucket. This method first deletes all objects from bucket and
* then delete empty bucket.
*
* @param bucketName the bucket name.
*/
public static void deleteBucket(final String bucketName) throws IOException {
Properties prop = readConfig(DEFAULT_CONFIG_FILE);
AmazonS3 s3service = openService(prop);
ObjectListing prevObjectListing = s3service.listObjects(bucketName);
while (true) {
for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries()) {
s3service.deleteObject(bucketName, s3ObjSumm.getKey());
}
if (!prevObjectListing.isTruncated()) {
break;
}
prevObjectListing = s3service.listNextBatchOfObjects(prevObjectListing);
}
s3service.deleteBucket(bucketName);
}
use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.
the class GetBucketPolicy method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage:\n" + " GetBucketPolicy <bucket>\n\n" + "Where:\n" + " bucket - the bucket to get the policy from.\n\n" + "Example:\n" + " GetBucketPolicy testbucket\n\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
String policy_text = null;
System.out.format("Getting policy for bucket: \"%s\"\n\n", bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
BucketPolicy bucket_policy = s3.getBucketPolicy(bucket_name);
policy_text = bucket_policy.getPolicyText();
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
if (policy_text == null) {
System.out.println("The specified bucket has no bucket policy.");
} else {
System.out.println("Returned policy:");
System.out.println("----");
System.out.println(policy_text);
System.out.println("----\n");
}
System.out.println("Done!");
}
use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.
the class GetObject method main.
public static void main(String[] args) {
final String USAGE = "\n" + "To run this example, supply the name of an S3 bucket and object to\n" + "download from it.\n" + "\n" + "Ex: GetObject <bucketname> <filename>\n";
if (args.length < 2) {
System.out.println(USAGE);
System.exit(1);
}
String bucket_name = args[0];
String key_name = args[1];
System.out.format("Downloading %s from S3 bucket %s...\n", key_name, bucket_name);
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
S3Object o = s3.getObject(bucket_name, key_name);
S3ObjectInputStream s3is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream(new File(key_name));
byte[] read_buf = new byte[1024];
int read_len = 0;
while ((read_len = s3is.read(read_buf)) > 0) {
fos.write(read_buf, 0, read_len);
}
s3is.close();
fos.close();
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
} catch (FileNotFoundException e) {
System.err.println(e.getMessage());
System.exit(1);
} catch (IOException e) {
System.err.println(e.getMessage());
System.exit(1);
}
System.out.println("Done!");
}
use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.
the class GetWebsiteConfiguration method getWebsiteConfig.
public static void getWebsiteConfig(String bucket_name) {
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
try {
BucketWebsiteConfiguration config = s3.getBucketWebsiteConfiguration(bucket_name);
if (config == null) {
System.out.println("No website configuration found!");
} else {
System.out.format("Index document: %s\n", config.getIndexDocumentSuffix());
System.out.format("Error document: %s\n", config.getErrorDocument());
}
} catch (AmazonServiceException e) {
System.err.println(e.getErrorMessage());
System.out.println("Failed to get website configuration!");
System.exit(1);
}
}
use of com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.
the class ListBuckets method main.
public static void main(String[] args) {
final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
List<Bucket> buckets = s3.listBuckets();
System.out.println("Your Amazon S3 buckets are:");
for (Bucket b : buckets) {
System.out.println("* " + b.getName());
}
}
Aggregations