Example usage for com.amazonaws.services.s3.model S3Object setObjectContent

List of usage examples for com.amazonaws.services.s3.model S3Object setObjectContent

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model S3Object setObjectContent.

Prototype

public void setObjectContent(InputStream objectContent) 

Source Link

Document

Sets the input stream containing this object's contents.

Usage

From source file:org.elasticsearch.repositories.s3.MockAmazonS3.java

License:Apache License

@Override
public S3Object getObject(GetObjectRequest getObjectRequest)
        throws AmazonClientException, AmazonServiceException {
    simulateS3SocketConnection();//from w ww  . j a v a  2s . c o  m
    // in ESBlobStoreContainerTestCase.java, the prefix is empty,
    // so the key and blobName are equivalent to each other
    String blobName = getObjectRequest.getKey();

    if (!blobs.containsKey(blobName)) {
        throw new AmazonS3Exception("[" + blobName + "] does not exist.");
    }

    // the HTTP request attribute is irrelevant for reading
    S3ObjectInputStream stream = new S3ObjectInputStream(blobs.get(blobName), null, false);
    S3Object s3Object = new S3Object();
    s3Object.setObjectContent(stream);
    return s3Object;
}

From source file:org.finra.dm.dao.impl.MockS3OperationsImpl.java

License:Apache License

@Override
public S3Object getS3Object(GetObjectRequest getObjectRequest, AmazonS3 s3) {
    String bucketName = getObjectRequest.getBucketName();
    String key = getObjectRequest.getKey();

    if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(bucketName)) {
        AmazonServiceException amazonServiceException = new AmazonServiceException(
                S3Operations.ERROR_CODE_NO_SUCH_BUCKET);
        amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_NO_SUCH_BUCKET);
        throw amazonServiceException;
    }/*from w w  w.  j a  v a2  s  . c  om*/

    if (MOCK_S3_BUCKET_NAME_ACCESS_DENIED.equals(bucketName)) {
        AmazonServiceException amazonServiceException = new AmazonServiceException(
                S3Operations.ERROR_CODE_ACCESS_DENIED);
        amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_ACCESS_DENIED);
        throw amazonServiceException;
    }

    if (MOCK_S3_BUCKET_NAME_INTERNAL_ERROR.equals(bucketName)) {
        AmazonServiceException amazonServiceException = new AmazonServiceException(
                S3Operations.ERROR_CODE_INTERNAL_ERROR);
        amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_INTERNAL_ERROR);
        throw amazonServiceException;
    }

    MockS3Bucket mockS3Bucket = getOrCreateBucket(bucketName);
    MockS3Object mockS3Object = mockS3Bucket.getObjects().get(key);

    if (mockS3Object == null) {
        AmazonServiceException amazonServiceException = new AmazonServiceException(
                S3Operations.ERROR_CODE_NO_SUCH_KEY);
        amazonServiceException.setErrorCode(S3Operations.ERROR_CODE_NO_SUCH_KEY);
        throw amazonServiceException;
    }

    S3Object s3Object = new S3Object();
    s3Object.setBucketName(bucketName);
    s3Object.setKey(key);
    s3Object.setObjectContent(new ByteArrayInputStream(mockS3Object.getData()));
    s3Object.setObjectMetadata(mockS3Object.getObjectMetadata());
    return s3Object;
}

From source file:org.finra.herd.dao.impl.MockS3OperationsImpl.java

License:Apache License

@Override
public S3Object getS3Object(GetObjectRequest getObjectRequest, AmazonS3 s3) {
    MockS3Object mockS3Object = getMockS3Object(getObjectRequest.getBucketName(), getObjectRequest.getKey());

    S3Object s3Object = new S3Object();
    s3Object.setBucketName(getObjectRequest.getBucketName());
    s3Object.setKey(getObjectRequest.getKey());
    s3Object.setObjectContent(new ByteArrayInputStream(mockS3Object.getData()));
    s3Object.setObjectMetadata(mockS3Object.getObjectMetadata());

    return s3Object;
}

From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java

License:Apache License

@Override
public CopyObjectResult copyObject(String sourceBucketName, String sourceKey, String destinationBucketName,
        String destinationKey) throws AmazonClientException, AmazonServiceException {

    S3Element element = find(sourceBucketName, sourceKey);

    if (element != null) {

        S3Object objectSource = element.getS3Object();
        // copy object with
        S3Object resObj = new S3Object();
        resObj.setBucketName(destinationBucketName);
        resObj.setKey(destinationKey);//from w w  w . ja  v a2s  . c  o  m
        resObj.setObjectContent(objectSource.getObjectContent());
        resObj.setObjectMetadata(objectSource.getObjectMetadata());
        resObj.setRedirectLocation(objectSource.getRedirectLocation());
        // copy perission
        AccessControlList permission = new AccessControlList();
        permission.setOwner(element.getPermission().getOwner());
        permission.grantAllPermissions(element.getPermission().getGrants().toArray(new Grant[0]));
        // maybe not exists key TODO
        objects.get(find(destinationBucketName))
                .add(new S3Element(resObj, permission, sourceKey.endsWith("/")));

        return new CopyObjectResult();
    }

    throw new AmazonServiceException("object source not found");
}

From source file:org.weakref.s3fs.util.AmazonS3ClientMock.java

License:Apache License

private S3Element parse(ByteArrayInputStream stream, String bucket, String key) {

    S3Object object = new S3Object();

    object.setBucketName(bucket);//w w w.jav a 2 s.  co m
    object.setKey(key);

    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setLastModified(new Date());
    metadata.setContentLength(stream.available());
    object.setObjectContent(stream);

    object.setObjectMetadata(metadata);
    // TODO: create converter between path permission and s3 permission
    AccessControlList permission = createAllPermission();
    return new S3Element(object, permission, false);
}