Example usage for com.amazonaws.services.s3.model ObjectMetadata ObjectMetadata

List of usage examples for com.amazonaws.services.s3.model ObjectMetadata ObjectMetadata

Introduction

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

Prototype

public ObjectMetadata() 

Source Link

Usage

From source file:org.elasticsearch.cloud.aws.blobstore.S3BlobContainer.java

License:Apache License

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {/*from w w  w  . ja v  a2  s  . c  o  m*/
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
                blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }
        blobStore.client().copyObject(request);
        blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}

From source file:org.elasticsearch.cloud.aws.blobstore.S3ImmutableBlobContainer.java

License:Apache License

@Override
public void writeBlob(final String blobName, final InputStream is, final long sizeInBytes,
        final WriterListener listener) {
    blobStore.executor().execute(new Runnable() {
        @Override//from  w w w  .ja v a 2s .co  m
        public void run() {
            try {
                ObjectMetadata md = new ObjectMetadata();
                if (blobStore.serverSideEncryption()) {
                    md.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
                }
                md.setContentLength(sizeInBytes);
                PutObjectResult objectResult = blobStore.client().putObject(blobStore.bucket(),
                        buildKey(blobName), is, md);
                listener.onCompleted();
            } catch (Exception e) {
                listener.onFailure(e);
            }
        }
    });
}

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

License:Apache License

protected void doUpload(S3BlobStore blobStore, String bucketName, String blobName, InputStream is, int length,
        boolean serverSideEncryption) throws AmazonS3Exception {
    ObjectMetadata md = new ObjectMetadata();
    if (serverSideEncryption) {
        md.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    }// ww  w . ja v  a 2  s.c  om
    md.setContentLength(length);

    PutObjectRequest putRequest = new PutObjectRequest(bucketName, blobName, is, md)
            .withStorageClass(blobStore.getStorageClass()).withCannedAcl(blobStore.getCannedACL());
    blobStore.client().putObject(putRequest);

}

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

License:Apache License

protected String doInitialize(S3BlobStore blobStore, String bucketName, String blobName,
        boolean serverSideEncryption) {
    InitiateMultipartUploadRequest request = new InitiateMultipartUploadRequest(bucketName, blobName)
            .withCannedACL(blobStore.getCannedACL()).withStorageClass(blobStore.getStorageClass());

    if (serverSideEncryption) {
        ObjectMetadata md = new ObjectMetadata();
        md.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
        request.setObjectMetadata(md);//  ww w  .  j av  a  2s .co m
    }

    return blobStore.client().initiateMultipartUpload(request).getUploadId();
}

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

License:Apache License

@Override
public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
        throws AmazonClientException, AmazonServiceException {
    simulateS3SocketConnection();// w w w .j a  v a 2 s  .com
    String blobName = getObjectMetadataRequest.getKey();

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

    return new ObjectMetadata(); // nothing is done with it
}

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

License:Apache License

@Override
public void move(String sourceBlobName, String targetBlobName) throws IOException {
    try {/*ww w.j av a 2s . co m*/
        CopyObjectRequest request = new CopyObjectRequest(blobStore.bucket(), buildKey(sourceBlobName),
                blobStore.bucket(), buildKey(targetBlobName));

        if (blobStore.serverSideEncryption()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            objectMetadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
            request.setNewObjectMetadata(objectMetadata);
        }

        SocketAccess.doPrivilegedVoid(() -> {
            blobStore.client().copyObject(request);
            blobStore.client().deleteObject(blobStore.bucket(), buildKey(sourceBlobName));
        });

    } catch (AmazonS3Exception e) {
        throw new IOException(e);
    }
}

From source file:org.entando.entando.plugins.jps3awsclient.aps.system.services.storage.AmazonS3StorageManager.java

License:Open Source License

public void store(IStorageObject obj, boolean reducedRedundancy, CannedAccessControlList acl)
        throws ApsSystemException {
    try {//from   w  w  w . ja v  a  2s.c om
        AmazonS3Client client = this.getS3Client();
        String bucketName = obj.getBucketName().toLowerCase();
        this.checkForAndCreateBucket(bucketName, client);
        ObjectMetadata omd = new ObjectMetadata();
        omd.setContentType(obj.getContentType());
        omd.setContentLength(obj.getContentLength());
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, obj.getStoragePath(),
                obj.getInputStream(), omd);
        // Check if reduced redundancy is enabled
        if (reducedRedundancy) {
            putObjectRequest.setStorageClass(StorageClass.ReducedRedundancy);
        }
        if (null != obj.getUserMetadata()) {
            ObjectMetadata objectMetadata = new ObjectMetadata();
            putObjectRequest.setMetadata(objectMetadata);
            Iterator<String> iter = obj.getUserMetadata().keySet().iterator();
            while (iter.hasNext()) {
                String key = iter.next();
                objectMetadata.addUserMetadata(key, obj.getUserMetadata().get(key));
            }
        }
        client.putObject(putObjectRequest);
        // If we have an ACL set access permissions for the the data on S3
        if (acl != null) {
            client.setObjectAcl(bucketName, obj.getStoragePath(), acl);
        }
    } catch (Throwable t) {
        _logger.error("Error storing object", t);
        throw new ApsSystemException("Error storing object", t);
    }
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public void createFolder(String bucketName, String key) {
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(0L);/* w  w w  .j a v a 2  s. com*/

    if (!StringUtils.endsWith(key, S3Constansts.DELIMITER)) {
        key = key.concat(S3Constansts.DELIMITER);
    }

    this.s3.putObject(bucketName, key, new ByteArrayInputStream(new byte[0]), metadata);
}

From source file:org.exem.flamingo.web.filesystem.s3.S3BrowserServiceImpl.java

License:Apache License

@Override
public void upload(String bucketName, String key, MultipartFile file) throws IOException {
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(file.getSize());
    PutObjectRequest request = new PutObjectRequest(bucketName, key, file.getInputStream(), metadata);
    this.s3.putObject(request);

}

From source file:org.fcrepo.modeshape.binary.S3BinaryStore.java

License:Apache License

@Override
public BinaryValue storeValue(InputStream stream, boolean markAsUnused) throws BinaryStoreException {
    // Cache file on the file system in order to have SHA-1 hash calculated
    BinaryValue cachedFile = fileSystemCache.storeValue(stream, markAsUnused);
    try {//w  w w  .  j  av  a  2  s.  c  om
        // Retrieve SHA-1 hash
        BinaryKey key = new BinaryKey(cachedFile.getKey().toString());

        // If file is NOT already in S3 storage, store it
        if (!s3Client.doesObjectExist(bucketName, key.toString())) {
            ObjectMetadata metadata = new ObjectMetadata();
            // Set Mimetype
            metadata.setContentType(fileSystemCache.getMimeType(cachedFile, key.toString()));
            // Set Unused value
            Map<String, String> userMetadata = metadata.getUserMetadata();
            userMetadata.put(UNUSED_KEY, String.valueOf(markAsUnused));
            metadata.setUserMetadata(userMetadata);
            // Store content in S3
            s3Client.putObject(bucketName, key.toString(), fileSystemCache.getInputStream(key), metadata);
        } else {
            // Set the unused value, if necessary
            if (markAsUnused) {
                markAsUnused(Collections.singleton(key));
            } else {
                markAsUsed(Collections.singleton(key));
            }
        }
        return new StoredBinaryValue(this, key, cachedFile.getSize());
    } catch (AmazonClientException | RepositoryException | IOException e) {
        throw new BinaryStoreException(e);
    } finally {
        // Remove cached file
        fileSystemCache.markAsUnused(Collections.singleton(cachedFile.getKey()));
        fileSystemCache.removeValuesUnusedLongerThan(1, TimeUnit.MICROSECONDS);
    }
}