Search in sources :

Example 1 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project camel by apache.

the class AmazonS3ClientMock method listBuckets.

@Override
public List<Bucket> listBuckets() throws AmazonClientException, AmazonServiceException {
    ArrayList<Bucket> list = new ArrayList<Bucket>();
    Bucket bucket = new Bucket("camel-bucket");
    bucket.setOwner(new Owner("Camel", "camel"));
    bucket.setCreationDate(new Date());
    list.add(bucket);
    return list;
}
Also used : Owner(com.amazonaws.services.s3.model.Owner) Bucket(com.amazonaws.services.s3.model.Bucket) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 2 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket 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 3 with Bucket

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

the class CreateBucket method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "CreateBucket - create an S3 bucket\n\n" + "Usage: CreateBucket <bucketname>\n\n" + "Where:\n" + "  bucketname - the name of the bucket to create.\n\n" + "The bucket name must be unique, or an error will result.\n";
    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucket_name = args[0];
    System.out.format("\nCreating S3 bucket: %s\n", bucket_name);
    Bucket b = createBucket(bucket_name);
    if (b == null) {
        System.out.println("Error creating bucket!\n");
    } else {
        System.out.println("Done!\n");
    }
}
Also used : Bucket(com.amazonaws.services.s3.model.Bucket)

Example 4 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket 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)

Example 5 with Bucket

use of com.talend.shaded.com.amazonaws.services.s3.model.Bucket in project tutorials by eugenp.

the class S3Application method main.

public static void main(String[] args) throws IOException {
    // set-up the client
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_2).build();
    AWSS3Service awsService = new AWSS3Service(s3client);
    bucketName = "baeldung-bucket";
    // creating a bucket
    if (awsService.doesBucketExist(bucketName)) {
        System.out.println("Bucket name is not available." + " Try again with a different Bucket name.");
        return;
    }
    awsService.createBucket(bucketName);
    // list all the buckets
    for (Bucket s : awsService.listBuckets()) {
        System.out.println(s.getName());
    }
    // deleting bucket
    awsService.deleteBucket("baeldung-bucket-test2");
    // uploading object
    awsService.putObject(bucketName, "Document/hello.txt", new File("/Users/user/Document/hello.txt"));
    // listing objects
    ObjectListing objectListing = awsService.listObjects(bucketName);
    for (S3ObjectSummary os : objectListing.getObjectSummaries()) {
        System.out.println(os.getKey());
    }
    // downloading an object
    S3Object s3object = awsService.getObject(bucketName, "Document/hello.txt");
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    FileUtils.copyInputStreamToFile(inputStream, new File("/Users/user/Desktop/hello.txt"));
    // copying an object
    awsService.copyObject("baeldung-bucket", "picture/pic.png", "baeldung-bucket2", "Document/picture.png");
    // deleting an object
    awsService.deleteObject(bucketName, "Document/hello.txt");
    // deleting multiple objects
    String[] objkeyArr = { "Document/hello2.txt", "Document/picture.png" };
    DeleteObjectsRequest delObjReq = new DeleteObjectsRequest("baeldung-bucket").withKeys(objkeyArr);
    awsService.deleteObjects(delObjReq);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) Bucket(com.amazonaws.services.s3.model.Bucket) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) S3ObjectInputStream(com.amazonaws.services.s3.model.S3ObjectInputStream) S3Object(com.amazonaws.services.s3.model.S3Object) File(java.io.File) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest)

Aggregations

Bucket (com.amazonaws.services.s3.model.Bucket)22 AmazonS3 (com.amazonaws.services.s3.AmazonS3)7 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 OperationContext (com.vmware.xenon.common.OperationContext)3 AmazonClientException (com.amazonaws.AmazonClientException)2 Regions (com.amazonaws.regions.Regions)2 BucketTaggingConfiguration (com.amazonaws.services.s3.model.BucketTaggingConfiguration)2 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 EnumerationAction (com.vmware.photon.controller.model.adapterapi.EnumerationAction)2 AWSConstants (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants)2 AWSResourceType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSResourceType)2 AwsClientType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType)2 BUCKET_OWNER_NAME (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.BUCKET_OWNER_NAME)2 STORAGE_TYPE_S3 (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_S3)2 AWSConstants.getQueryResultLimit (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.getQueryResultLimit)2 AWSUriPaths (com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths)2