List of usage examples for com.amazonaws.services.s3.model ObjectMetadata setSSEAlgorithm
@Override public void setSSEAlgorithm(String algorithm)
From source file:org.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
/** * Prepares the object metadata for server side encryption and reduced redundancy storage. * * @param params the parameters./* ww w.ja va 2 s .c o m*/ * @param metadata the metadata to prepare. */ private void prepareMetadata(final S3FileTransferRequestParamsDto params, ObjectMetadata metadata) { // Set the server side encryption if (params.getKmsKeyId() != null) { /* * TODO Use proper way to set KMS once AWS provides a way. * We are modifying the raw headers directly since TransferManager's uploadFileList operation does not provide a way to set a KMS key ID. * This would normally cause some issues when uploading where an MD5 checksum validation exception will be thrown, even though the object is * correctly uploaded. * To get around this, a system property defined at * com.amazonaws.services.s3.internal.SkipMd5CheckStrategy.DISABLE_PUT_OBJECT_MD5_VALIDATION_PROPERTY must be set. */ metadata.setSSEAlgorithm(SSEAlgorithm.KMS.getAlgorithm()); metadata.setHeader(Headers.SERVER_SIDE_ENCRYPTION_AWS_KMS_KEYID, params.getKmsKeyId().trim()); } else { metadata.setSSEAlgorithm(SSEAlgorithm.AES256.getAlgorithm()); } // If specified, set the metadata to use RRS. if (Boolean.TRUE.equals(params.isUseRrs())) { // TODO: For upload File, we can set RRS on the putObjectRequest. For uploadDirectory, this is the only // way to do it. However, setHeader() is flagged as For Internal Use Only metadata.setHeader(Headers.STORAGE_CLASS, StorageClass.ReducedRedundancy.toString()); } }
From source file:sample.S3EmitterWithMetadata.java
License:Open Source License
@Override public List<byte[]> emit(final UnmodifiableBuffer<byte[]> buffer) throws IOException { List<byte[]> records = buffer.getRecords(); // Write all of the records to a compressed output stream ByteArrayOutputStream baos = new ByteArrayOutputStream(); for (byte[] record : records) { try {/*from w w w. ja v a 2 s .c o m*/ baos.write(record); } catch (Exception e) { LOG.error("Error writing record to output stream. Failing this emit attempt. Record: " + Arrays.toString(record), e); return buffer.getRecords(); } } // Get the Amazon S3 filename String s3FileName = getS3FileName(buffer.getFirstSequenceNumber(), buffer.getLastSequenceNumber()); String s3URI = getS3URI(s3FileName); try { ByteArrayInputStream object = new ByteArrayInputStream(baos.toByteArray()); LOG.debug("Starting upload of file " + s3URI + " to Amazon S3 containing " + records.size() + " records."); ObjectMetadata meta = new ObjectMetadata(); Date date = new Date(); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(date); calendar.add(Calendar.DATE, 14); meta.setExpirationTime(calendar.getTime()); meta.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION); meta.setContentLength(baos.size()); s3client.putObject(s3Bucket, s3FileName, object, meta); LOG.info("Successfully emitted " + buffer.getRecords().size() + " records to Amazon S3 in " + s3URI); return Collections.emptyList(); } catch (Exception e) { LOG.error("Caught exception when uploading file " + s3URI + "to Amazon S3. Failing this emit attempt.", e); return buffer.getRecords(); } }