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

The following are Jave code examples for showing how to use addUserMetadata() 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: urlshortner   File: UrlShortnerService.java   Source Code and License Vote up 6 votes
/**
 * The method creates a short URL code for the given url
 * 
 * @param url
 * @return
 */
public ShortUrl createShortUrl(String url, String code) {

	logger.info("storing the url {} in the bucket {}", url, this.bucket);
	// Create the link for the short code
	if (code == null) {
		code = getObjectCode();
	}
	String loadFile = redirectFile.replace("REPLACE", url);
	byte[] fileContentBytes = loadFile.getBytes(StandardCharsets.UTF_8);
	InputStream fileInputStream = new ByteArrayInputStream(fileContentBytes);
	ObjectMetadata metadata = new ObjectMetadata();
	metadata.setContentType("text/html");
	metadata.addUserMetadata("url", url);
	metadata.setContentLength(fileContentBytes.length);
	PutObjectRequest putObjectRequest = new PutObjectRequest(this.bucket, code, fileInputStream, metadata)
			.withCannedAcl(CannedAccessControlList.PublicRead);
	this.s3Client.putObject(putObjectRequest);
	createDummyRecord(url, code);
	return new ShortUrl(url, code);
}
 
Example 2
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 3
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 4
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);
}
 
Example 5
Project: ibm-cos-sdk-java   File: ContentCryptoMaterial.java   Source Code and License Vote up 5 votes
/**
 * Returns the metadata in the latest format.
 */
private ObjectMetadata toObjectMetadata(ObjectMetadata metadata) {
    // If we generated a symmetric key to encrypt the data, store it in the
    // object metadata.
    byte[] encryptedCEK = getEncryptedCEK();
    metadata.addUserMetadata(Headers.CRYPTO_KEY_V2,
            Base64.encodeAsString(encryptedCEK));
    // Put the cipher initialization vector (IV) into the object metadata
    byte[] iv = cipherLite.getIV();
    metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv));
    // Put the materials description into the object metadata as JSON
    metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION,
            kekMaterialDescAsJson());
    // The CRYPTO_CEK_ALGORITHM, CRYPTO_TAG_LENGTH and
    // CRYPTO_KEYWRAP_ALGORITHM were not available in the Encryption Only
    // (EO) implementation
    ContentCryptoScheme scheme = getContentCryptoScheme();
    metadata.addUserMetadata(Headers.CRYPTO_CEK_ALGORITHM,
            scheme.getCipherAlgorithm());
    int tagLen = scheme.getTagLengthInBits();
    if (tagLen > 0)
        metadata.addUserMetadata(Headers.CRYPTO_TAG_LENGTH,
                String.valueOf(tagLen));
    String keyWrapAlgo = getKeyWrappingAlgorithm();
    if (keyWrapAlgo != null)
        metadata.addUserMetadata(Headers.CRYPTO_KEYWRAP_ALGORITHM,
                keyWrapAlgo);
    return metadata;
}
 
Example 6
Project: ibm-cos-sdk-java   File: ContentCryptoMaterial.java   Source Code and License Vote up 5 votes
/**
 * Returns the metadata in backward compatibility (old) format, so it can be
 * read by older version of the AWS SDK.
 */
private ObjectMetadata toObjectMetadataEO(ObjectMetadata metadata) {
    // If we generated a symmetric key to encrypt the data, store it in the
    // object metadata.
    byte[] encryptedCEK = getEncryptedCEK();
    metadata.addUserMetadata(Headers.CRYPTO_KEY,
            Base64.encodeAsString(encryptedCEK));
    // Put the cipher initialization vector (IV) into the object metadata
    byte[] iv = cipherLite.getIV();
    metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv));
    // Put the materials description into the object metadata as JSON
    metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION,
            kekMaterialDescAsJson());
    return metadata;
}
 
Example 7
Project: ibm-cos-sdk-java   File: S3CryptoModuleBase.java   Source Code and License Vote up 5 votes
protected final PutObjectRequest createInstructionPutRequest(
        String bucketName, String key, ContentCryptoMaterial cekMaterial) {
    byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode())
                              .getBytes(UTF8);
    InputStream is = new ByteArrayInputStream(bytes);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(bytes.length);
    metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, "");
    InstructionFileId ifileId = new S3ObjectId(bucketName, key)
            .instructionFileId();
    return new PutObjectRequest(ifileId.getBucket(), ifileId.getKey(),
        is, metadata);
}