Java Code Examples for com.amazonaws.services.s3.model.ObjectMetadata.setHeader()

The following are Jave code examples for showing how to use setHeader() of the com.amazonaws.services.s3.model.ObjectMetadata class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hollow-reference-implementation   File: S3Publisher.java   Source Code and License Vote up 6 votes
/**
 * Write a list of all of the state versions to S3.
 * @param newVersion
 */
private synchronized void updateSnapshotIndex(Long newVersion) {
	/// insert the new version into the list
	int idx = Collections.binarySearch(snapshotIndex, newVersion);
	int insertionPoint = Math.abs(idx) - 1;
	snapshotIndex.add(insertionPoint, newVersion);
	
	/// build a binary representation of the list -- gap encoded variable-length integers
	byte[] idxBytes = buidGapEncodedVarIntSnapshotIndex();
	
	/// indicate the Content-Length
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setHeader("Content-Length", (long)idxBytes.length);
	
    /// upload the new file content.
    try(InputStream is = new ByteArrayInputStream(idxBytes)) {
        Upload upload = s3TransferManager.upload(bucketName, getSnapshotIndexObjectName(blobNamespace), is, metadata);
        
        upload.waitForCompletion();
    } catch(Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Project: rxjava2-aws   File: Sqs.java   Source Code and License Vote up 5 votes
public static String sendToQueueUsingS3(AmazonSQS sqs, String queueUrl, AmazonS3 s3, String bucketName,
        Map<String, String> headers, byte[] message, Callable<String> s3IdFactory) {
    Preconditions.checkNotNull(sqs);
    Preconditions.checkNotNull(s3);
    Preconditions.checkNotNull(queueUrl);
    Preconditions.checkNotNull(bucketName);
    Preconditions.checkNotNull(message);
    String s3Id;
    try {
        s3Id = s3IdFactory.call();
    } catch (final Exception e1) {
        throw new RuntimeException(e1);
    }
    final ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(message.length);
    for (final Entry<String, String> header : headers.entrySet()) {
        metadata.setHeader(header.getKey(), header.getValue());
    }
    s3.putObject(bucketName, s3Id, new ByteArrayInputStream(message), metadata);
    try {
        sqs.sendMessage(queueUrl, s3Id);
    } catch (final RuntimeException e) {
        try {
            s3.deleteObject(bucketName, s3Id);
            throw e;
        } catch (final RuntimeException e2) {
            throw new io.reactivex.exceptions.CompositeException(e, e2);
        }
    }
    return s3Id;
}
 
Example 3
Project: hollow-reference-implementation   File: S3Publisher.java   Source Code and License Vote up 5 votes
public void publishSnapshot(Blob blob) {
    String objectName = getS3ObjectName(blobNamespace, "snapshot", blob.getToVersion());

    ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion()));
    metadata.setHeader("Content-Length", blob.getFile().length());
    
    uploadFile(blob.getFile(), objectName, metadata);
    
    /// now we update the snapshot index
    updateSnapshotIndex(blob.getToVersion());
}
 
Example 4
Project: hollow-reference-implementation   File: S3Publisher.java   Source Code and License Vote up 5 votes
public void publishDelta(Blob blob) {
    String objectName = getS3ObjectName(blobNamespace, "delta", blob.getFromVersion());
    
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("from_state", String.valueOf(blob.getFromVersion()));
    metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion()));
    metadata.setHeader("Content-Length", blob.getFile().length());
    
    uploadFile(blob.getFile(), objectName, metadata);
}
 
Example 5
Project: hollow-reference-implementation   File: S3Publisher.java   Source Code and License Vote up 5 votes
public void publishReverseDelta(Blob blob) {
    String objectName = getS3ObjectName(blobNamespace, "reversedelta", blob.getFromVersion());
    
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.addUserMetadata("from_state", String.valueOf(blob.getFromVersion()));
    metadata.addUserMetadata("to_state", String.valueOf(blob.getToVersion()));
    metadata.setHeader("Content-Length", blob.getFile().length());
    
    uploadFile(blob.getFile(), objectName, metadata);
}