Search in sources :

Example 41 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project h2o-2 by h2oai.

the class TypeaheadFileRequest method serveS3.

protected JsonArray serveS3(String filter, int limit) {
    JsonArray array = new JsonArray();
    try {
        AmazonS3 s3 = PersistS3.getClient();
        filter = Strings.nullToEmpty(filter);
        for (Bucket b : s3.listBuckets()) {
            if (b.getName().startsWith(filter))
                array.add(new JsonPrimitive(b.getName()));
            if (array.size() == limit)
                break;
        }
    } catch (IllegalArgumentException xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 42 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project h2o-2 by h2oai.

the class TypeaheadS3BucketRequest method serve.

@Override
protected JsonArray serve(String filter, int limit) {
    JsonArray array = new JsonArray();
    try {
        AmazonS3 s3 = PersistS3.getClient();
        filter = Strings.nullToEmpty(filter);
        for (Bucket b : s3.listBuckets()) {
            if (b.getName().startsWith(filter))
                array.add(new JsonPrimitive(b.getName()));
            if (array.size() == limit)
                break;
        }
    } catch (IllegalArgumentException xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 43 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project crate by crate.

the class S3ClientHelperTest method testWithCredentials.

@Test
public void testWithCredentials() throws Exception {
    AmazonS3 s3Client = s3ClientHelper.client(new URI("s3://user:password@host/path"));
    URL url = s3Client.generatePresignedUrl("bucket", "key", new Date(0L));
    assertThat(url.toString(), is("https://bucket.s3.amazonaws.com/key?AWSAccessKeyId=user&Expires=0&Signature=o5V2voSQbVEErsUXId6SssCq9OY%3D"));
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) URI(java.net.URI) URL(java.net.URL) Date(java.util.Date) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 44 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project deeplearning4j by deeplearning4j.

the class S3Downloader method paginate.

/**
     * Paginates through a bucket's keys invoking the listener 
     * at each key
     * @param bucket the bucket to iterate
     * @param listener the listener
     */
public void paginate(String bucket, BucketKeyListener listener) {
    AmazonS3 s3 = getClient();
    ObjectListing list = s3.listObjects(bucket);
    for (S3ObjectSummary summary : list.getObjectSummaries()) {
        if (listener != null)
            listener.onKey(s3, bucket, summary.getKey());
    }
    while (list.isTruncated()) {
        list = s3.listNextBatchOfObjects(list);
        for (S3ObjectSummary summary : list.getObjectSummaries()) {
            if (listener != null)
                listener.onKey(s3, bucket, summary.getKey());
        }
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3)

Example 45 with AmazonS3

use of com.amazonaws.services.s3.AmazonS3 in project deeplearning4j by deeplearning4j.

the class S3Downloader method listObjects.

/**
     * Simple way of retrieving the listings for a bucket
     * @param bucket the bucket to retrieve listings for
     * @return the object listing for this bucket
     */
public ObjectListing listObjects(String bucket) {
    AmazonS3 s3 = getClient();
    ObjectListing list = s3.listObjects(bucket);
    return list;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)55 AmazonServiceException (com.amazonaws.AmazonServiceException)15 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)10 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)10 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)9 Bucket (com.amazonaws.services.s3.model.Bucket)6 ArrayList (java.util.ArrayList)6 ClientConfiguration (com.amazonaws.ClientConfiguration)5 S3Object (com.amazonaws.services.s3.model.S3Object)5 Test (org.junit.Test)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)4 Configuration (org.apache.hadoop.conf.Configuration)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 S3ClientOptions (com.amazonaws.services.s3.S3ClientOptions)3 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 AmazonClientException (com.amazonaws.AmazonClientException)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 BucketWebsiteConfiguration (com.amazonaws.services.s3.model.BucketWebsiteConfiguration)2