Search in sources :

Example 21 with AmazonS3

use of com.talend.shaded.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);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) BucketWebsiteConfiguration(com.amazonaws.services.s3.model.BucketWebsiteConfiguration) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 22 with AmazonS3

use of com.talend.shaded.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());
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket)

Example 23 with AmazonS3

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 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());
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary)

Example 24 with AmazonS3

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.

the class CopyObject method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "To run this example, supply the name (key) of an S3 object, the bucket name\n" + "that it's contained within, and the bucket to copy it to.\n" + "\n" + "Ex: CopyObject <objectname> <frombucket> <tobucket>\n";
    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String object_key = args[0];
    String from_bucket = args[1];
    String to_bucket = args[2];
    System.out.format("Copying object %s from bucket %s to %s\n", object_key, from_bucket, to_bucket);
    final AmazonS3 s3 = new AmazonS3Client();
    try {
        s3.copyObject(from_bucket, object_key, to_bucket, object_key);
    } catch (AmazonServiceException e) {
        System.err.println(e.getErrorMessage());
        System.exit(1);
    }
    System.out.println("Done!");
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonServiceException(com.amazonaws.AmazonServiceException)

Example 25 with AmazonS3

use of com.talend.shaded.com.amazonaws.services.s3.AmazonS3 in project aws-doc-sdk-examples by awsdocs.

the class CreateBucket method getBucket.

public static Bucket getBucket(String bucket_name) {
    final AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();
    Bucket named_bucket = null;
    List<Bucket> buckets = s3.listBuckets();
    for (Bucket b : buckets) {
        if (b.getName().equals(bucket_name)) {
            named_bucket = b;
        }
    }
    return named_bucket;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)85 AmazonServiceException (com.amazonaws.AmazonServiceException)16 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)13 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)13 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)12 File (java.io.File)11 Test (org.junit.Test)11 S3Object (com.amazonaws.services.s3.model.S3Object)10 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)7 Bucket (com.amazonaws.services.s3.model.Bucket)7 ArrayList (java.util.ArrayList)7 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)6 AmazonClientException (com.amazonaws.AmazonClientException)5 ClientConfiguration (com.amazonaws.ClientConfiguration)5 Regions (com.amazonaws.regions.Regions)4 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)4 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)4 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Configuration (org.apache.hadoop.conf.Configuration)4