Search in sources :

Example 11 with Download

use of com.amazonaws.services.s3.transfer.Download in project gradle by gradle.

the class S3Client method doGetS3Object.

private S3Object doGetS3Object(URI uri, boolean isLightWeight) {
    S3RegionalResource s3RegionalResource = new S3RegionalResource(uri);
    String bucketName = s3RegionalResource.getBucketName();
    String s3BucketKey = s3RegionalResource.getKey();
    configureClient(s3RegionalResource);
    GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, s3BucketKey);
    if (isLightWeight) {
        // Skip content download
        getObjectRequest.setRange(0, 0);
    }
    try {
        return amazonS3Client.getObject(getObjectRequest);
    } catch (AmazonServiceException e) {
        String errorCode = e.getErrorCode();
        if (null != errorCode && errorCode.equalsIgnoreCase("NoSuchKey")) {
            return null;
        }
        throw ResourceExceptions.getFailed(uri, e);
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)2 S3Object (com.amazonaws.services.s3.model.S3Object)2 File (java.io.File)2 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 ProgressEvent (com.amazonaws.event.ProgressEvent)1 ProgressListener (com.amazonaws.event.ProgressListener)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 AbortMultipartUploadRequest (com.amazonaws.services.s3.model.AbortMultipartUploadRequest)1 CompleteMultipartUploadRequest (com.amazonaws.services.s3.model.CompleteMultipartUploadRequest)1 CompleteMultipartUploadResult (com.amazonaws.services.s3.model.CompleteMultipartUploadResult)1 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)1 InitiateMultipartUploadResult (com.amazonaws.services.s3.model.InitiateMultipartUploadResult)1 PartETag (com.amazonaws.services.s3.model.PartETag)1 ProgressEvent (com.amazonaws.services.s3.model.ProgressEvent)1 ProgressListener (com.amazonaws.services.s3.model.ProgressListener)1