Search in sources :

Example 46 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project YCSB by brianfrankcooper.

the class S3Client method getS3ObjectAndMetadata.

private Map.Entry<S3Object, ObjectMetadata> getS3ObjectAndMetadata(String bucket, String key, SSECustomerKey ssecLocal) {
    GetObjectRequest getObjectRequest;
    GetObjectMetadataRequest getObjectMetadataRequest;
    if (ssecLocal != null) {
        getObjectRequest = new GetObjectRequest(bucket, key).withSSECustomerKey(ssecLocal);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key).withSSECustomerKey(ssecLocal);
    } else {
        getObjectRequest = new GetObjectRequest(bucket, key);
        getObjectMetadataRequest = new GetObjectMetadataRequest(bucket, key);
    }
    return new AbstractMap.SimpleEntry<>(s3Client.getObject(getObjectRequest), s3Client.getObjectMetadata(getObjectMetadataRequest));
}
Also used : GetObjectMetadataRequest(com.amazonaws.services.s3.model.GetObjectMetadataRequest) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 47 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project gradle by gradle.

the class S3Resource method getMetaData.

public ExternalResourceMetaData getMetaData() {
    ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
    Date lastModified = objectMetadata.getLastModified();
    return new DefaultExternalResourceMetaData(uri, lastModified.getTime(), getContentLength(), s3Object.getObjectMetadata().getContentType(), s3Object.getObjectMetadata().getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
    null);
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DefaultExternalResourceMetaData(org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData) Date(java.util.Date)

Example 48 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project gradle by gradle.

the class S3ResourceConnector method getMetaData.

public ExternalResourceMetaData getMetaData(URI location, boolean revalidate) {
    LOGGER.debug("Attempting to get resource metadata: {}", location);
    S3Object s3Object = s3Client.getMetaData(location);
    if (s3Object == null) {
        return null;
    }
    try {
        ObjectMetadata objectMetadata = s3Object.getObjectMetadata();
        return new DefaultExternalResourceMetaData(location, objectMetadata.getLastModified().getTime(), objectMetadata.getContentLength(), objectMetadata.getContentType(), objectMetadata.getETag(), // Passing null for sha1 - TODO - consider using the etag which is an MD5 hash of the file (when less than 5Gb)
        null);
    } finally {
        IoActions.closeQuietly(s3Object);
    }
}
Also used : S3Object(com.amazonaws.services.s3.model.S3Object) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) DefaultExternalResourceMetaData(org.gradle.internal.resource.metadata.DefaultExternalResourceMetaData)

Example 49 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project airpal by airbnb.

the class S3FilesResource method getFile.

@GET
@Path("/{filename}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getFile(@PathParam("filename") String filename) {
    val outputKey = getOutputKey(filename);
    val getRequest = new GetObjectRequest(outputBucket, outputKey);
    final val object = s3Client.getObject(getRequest);
    if (object == null) {
        return Response.status(Response.Status.NOT_FOUND).build();
    } else {
        ObjectMetadata objectMetadata = object.getObjectMetadata();
        Response.ResponseBuilder builder = Response.ok().type(objectMetadata.getContentType());
        if (objectMetadata.getContentEncoding() != null) {
            // gzip
            builder = builder.encoding(objectMetadata.getContentEncoding());
        }
        return builder.entity(new StreamingOutput() {

            @Override
            public void write(OutputStream output) throws IOException, WebApplicationException {
                try (InputStream objectData = object.getObjectContent()) {
                    ByteStreams.copy(objectData, output);
                } finally {
                    output.close();
                }
            }
        }).build();
    }
}
Also used : lombok.val(lombok.val) Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) StreamingOutput(javax.ws.rs.core.StreamingOutput) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 50 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project ice by Netflix.

the class BasicS3ApplicationGroupService method saveApplicationGroup.

public boolean saveApplicationGroup(ApplicationGroup appgroup) {
    Map<String, ApplicationGroup> appgroups = getApplicationGroups();
    appgroups.put(appgroup.name, appgroup);
    try {
        String json = getJson(appgroups);
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups", IOUtils.toInputStream(json), new ObjectMetadata());
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy_appgroups", IOUtils.toInputStream(json), new ObjectMetadata());
        BasicS3ApplicationGroupService.logger.info("saved appgroup " + appgroup);
        return true;
    } catch (JSONException e) {
        logger.error("Error saving appgroup " + appgroup, e);
        return false;
    }
}
Also used : ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) JSONException(org.json.JSONException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)75 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)26 IOException (java.io.IOException)19 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 AmazonClientException (com.amazonaws.AmazonClientException)17 AmazonServiceException (com.amazonaws.AmazonServiceException)17 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)10 Upload (com.amazonaws.services.s3.transfer.Upload)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 InputStream (java.io.InputStream)9 Copy (com.amazonaws.services.s3.transfer.Copy)8 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)7 File (java.io.File)5 InterruptedIOException (java.io.InterruptedIOException)5 Date (java.util.Date)5 Path (org.apache.hadoop.fs.Path)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)3