Example usage for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client

List of usage examples for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3Client AmazonS3Client.

Prototype

@SdkInternalApi
AmazonS3Client(AmazonS3ClientParams s3ClientParams) 

Source Link

Document

Constructs a new client to invoke service methods on S3 using the specified parameters.

Usage

From source file:com.proofpoint.galaxy.coordinator.AwsProvisionerModule.java

License:Apache License

@Provides
@Singleton
public AmazonS3 providesS3(AWSCredentials awsCredentials) {
    return new AmazonS3Client(awsCredentials);
}

From source file:com.qubole.presto.kinesis.KinesisClientManager.java

License:Apache License

@Inject
KinesisClientManager(KinesisConnectorConfig kinesisConnectorConfig) {
    log.info("Creating new client for Consumer");
    if (nonEmpty(kinesisConnectorConfig.getAccessKey()) && nonEmpty(kinesisConnectorConfig.getSecretKey())) {
        this.kinesisAwsCredentials = new KinesisAwsCredentials(kinesisConnectorConfig.getAccessKey(),
                kinesisConnectorConfig.getSecretKey());
        this.client = new AmazonKinesisClient(this.kinesisAwsCredentials);
        this.amazonS3Client = new AmazonS3Client(this.kinesisAwsCredentials);
        this.dynamoDBClient = new AmazonDynamoDBClient(this.kinesisAwsCredentials);
    } else {//from  ww  w .  j  a v a 2  s . com
        this.kinesisAwsCredentials = null;
        DefaultAWSCredentialsProviderChain defaultChain = new DefaultAWSCredentialsProviderChain();
        this.client = new AmazonKinesisClient(defaultChain);
        this.amazonS3Client = new AmazonS3Client(defaultChain);
        this.dynamoDBClient = new AmazonDynamoDBClient(defaultChain);
    }

    this.client.setEndpoint("kinesis." + kinesisConnectorConfig.getAwsRegion() + ".amazonaws.com");
    this.dynamoDBClient.setEndpoint("dynamodb." + kinesisConnectorConfig.getAwsRegion() + ".amazonaws.com");
}

From source file:com.qubole.qds.sdk.java.client.ResultStreamer.java

License:Apache License

@VisibleForTesting
protected S3Client newS3Client() throws Exception {
    Account account = getAccount();// ww  w.j  a  v  a2s.  c o m
    AWSCredentials awsCredentials = new BasicAWSCredentials(account.getStorage_access_key(),
            account.getStorage_secret_key());
    final AmazonS3Client client = new AmazonS3Client(awsCredentials);
    return new S3Client() {
        @Override
        public void shutdown() {
            client.shutdown();
        }

        @Override
        public ObjectListing listObjects(ListObjectsRequest listObjectsRequest) {
            return client.listObjects(listObjectsRequest);
        }

        @Override
        public S3Object getObject(String bucket, String key) {
            return client.getObject(bucket, key);
        }
    };
}

From source file:com.rathravane.clerk.impl.s3.S3IamDb.java

License:Apache License

protected S3IamDb(String apiKey, String privateKey, String bucket, String prefix, AclFactory aclFactory) {
    super(aclFactory);

    fDb = new AmazonS3Client(new S3Creds(apiKey, privateKey));
    fBucketId = bucket;/*from  w  w w  . j ava2s .  co m*/
    fPrefix = prefix;
    fCache = new lruCache<String, JSONObject>(1024); // FIXME: clean caching
}

From source file:com.readystatesoftware.simpl3r.example.UploadService.java

License:Apache License

@Override
public void onCreate() {
    super.onCreate();
    s3Client = new AmazonS3Client(
            new BasicAWSCredentials(getString(R.string.s3_access_key), getString(R.string.s3_secret)));
    nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    IntentFilter f = new IntentFilter();
    f.addAction(UPLOAD_CANCELLED_ACTION);
    registerReceiver(uploadCancelReceiver, f);
}

From source file:com.saife.sample.S3Sample.java

License:Apache License

/**
 * /*w  w w.j  av a  2s .  c  o  m*/
 */
private void initS3() {
    // S3 credential identity
    final String me = "john.curtis@saife-tiprnet";

    AWSCredentials credentials = null;
    try {
        credentials = new ProfileCredentialsProvider(me).getCredentials();
    } catch (final Exception e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/home/builder/.aws/credentials), and is in valid format.", e);
    }

    s3 = new AmazonS3Client(credentials);
    final Region usWest2 = Region.getRegion(Regions.US_WEST_2);
    s3.setRegion(usWest2);

    // define a bucket name
    bucketName = null;

    try {

        /*
         * List the buckets in your account
         */
        for (final Bucket bucket : s3.listBuckets()) {
            if (bucket.getName().startsWith("saife-test-bucket")) {
                bucketName = bucket.getName();
                System.out.println("Found Test Bucket:" + bucket.getName());
            }
        }

        /*
         * Create a globally unique bucket name if needed.
         */
        if (null == bucketName) {
            bucketName = "saife-test-bucket" + UUID.randomUUID();
            System.out.println("Creating bucket " + bucketName + "\n");
            s3.createBucket(bucketName);
        }
    } catch (final AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which means your request made it "
                + "to Amazon S3, but was rejected with an error response for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
    } catch (final AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which means the client encountered "
                + "a serious internal problem while trying to communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
    }

    System.out.println("S3 services are enabled.");
}

From source file:com.scoyo.tools.s3cacheenhancer.cli.CLI.java

License:Apache License

private static S3HeaderEnhancer buildS3HeaderEnhancer(HeaderEnhancerArguments arguments) {
    AWSCredentials credentials = new BasicAWSCredentials(arguments.awsAccessKey, arguments.awsSecretKey);
    AmazonS3 s3 = new AmazonS3Client(credentials);
    S3HeaderEnhancer enhancer = new S3HeaderEnhancer(s3, arguments.bucketName, arguments.prefix);

    if (arguments.maxAge != null) {
        enhancer.setMaxAge(arguments.maxAge);
    }// ww w .ja  va  2  s .c  o  m
    if (arguments.maxThreads != null) {
        enhancer.setMaxThreads(arguments.maxThreads.intValue());
    }
    return enhancer;
}

From source file:com.screensaver.util.Util.java

License:Open Source License

/**
 * Gets an instance of a S3 client which is constructed using the given
 * Context.//from www  .java2s  .  c om
 *
 * @param context An Context instance.
 * @return A default S3 client.
 */
public static AmazonS3Client getS3Client(Context context) {
    if (sS3Client == null) {
        sS3Client = new AmazonS3Client(getCredProvider(context.getApplicationContext()));
        sS3Client.setRegion(Region.getRegion(Regions.fromName(Constants.BUCKET_REGION)));
    }
    return sS3Client;
}

From source file:com.shareplaylearn.models.UserItemManager.java

License:Open Source License

public Response getItem(String contentType, ItemSchema.PresentationType presentationType, String name,
        String encoding) {/*from w w  w  .j av a  2  s.  c  o  m*/
    if (encoding != null && encoding.length() > 0 && !AvailableEncodings.isAvailable(encoding)) {
        return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE)
                .entity("Inner Encoding Type: " + encoding + " not available").build();
    }

    AmazonS3Client s3Client = new AmazonS3Client(
            new BasicAWSCredentials(SecretsService.amazonClientId, SecretsService.amazonClientSecret));

    try {
        S3Object object = s3Client.getObject(ItemSchema.S3_BUCKET,
                getItemLocation(name, contentType, presentationType));
        try (S3ObjectInputStream inputStream = object.getObjectContent()) {
            long contentLength = object.getObjectMetadata().getContentLength();
            if (contentLength > Limits.MAX_RETRIEVE_SIZE) {
                throw new IOException("Object is to large: " + contentLength + " bytes.");
            }
            int bufferSize = Math.min((int) contentLength, 10 * 8192);
            byte[] buffer = new byte[bufferSize];
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            int bytesRead = 0;
            int totalBytesRead = 0;
            while ((bytesRead = inputStream.read(buffer)) > 0) {
                outputStream.write(buffer, 0, bytesRead);
                totalBytesRead += bytesRead;
            }
            log.debug("GET in file resource read: " + totalBytesRead + " bytes.");
            if (encoding == null || encoding.length() == 0 || encoding.equals(AvailableEncodings.IDENTITY)) {
                return Response.status(Response.Status.OK).entity(outputStream.toByteArray()).build();
            } else if (encoding.equals(AvailableEncodings.BASE64)) {
                return Response.status(Response.Status.OK)
                        .entity(Base64.encodeAsString(outputStream.toByteArray())).build();
            } else {
                return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE)
                        .entity("Inner Encoding Type: " + encoding + " not available").build();
            }
        }
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        pw.println("\nFailed to retrieve: " + name);
        e.printStackTrace(pw);
        log.warn("Failed to retrieve: " + name);
        log.info(Exceptions.asString(e));
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(sw.toString()).build();
    }
}

From source file:com.shareplaylearn.models.UserItemManager.java

License:Open Source License

/**
 * Writes items to S3, and item metadata to Redis
 *//*w  w  w  . j a  v  a  2 s.c o m*/
private void saveItem(String name, byte[] itemData, String contentType,
        ItemSchema.PresentationType presentationType) throws InternalErrorException {

    String itemLocation = this.getItemLocation(name, contentType, presentationType);
    AmazonS3Client s3Client = new AmazonS3Client(
            new BasicAWSCredentials(SecretsService.amazonClientId, SecretsService.amazonClientSecret));
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(itemData);
    ObjectMetadata metadata = this.makeBasicMetadata(itemData.length, false, name);
    metadata.addUserMetadata(UploadMetadataFields.CONTENT_TYPE, contentType);
    //TODO: save this metadata, along with location, to local Redis
    s3Client.putObject(ItemSchema.S3_BUCKET, itemLocation, byteArrayInputStream, metadata);
}