本文整理汇总了Java中com.amazonaws.util.Md5Utils类的典型用法代码示例。如果您正苦于以下问题:Java Md5Utils类的具体用法?Java Md5Utils怎么用?Java Md5Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Md5Utils类属于com.amazonaws.util包,在下文中一共展示了Md5Utils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: populateSSE_C
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
/**
* <p>
* Populates the specified request with the numerous attributes available in
* <code>SSEWithCustomerKeyRequest</code>.
* </p>
*
* @param request
* The request to populate with headers to represent all the
* options expressed in the
* <code>ServerSideEncryptionWithCustomerKeyRequest</code>
* object.
* @param sseKey
* The request object for an S3 operation that allows server-side
* encryption using customer-provided keys.
*/
private static void populateSSE_C(Request<?> request, SSECustomerKey sseKey) {
if (sseKey == null) return;
addHeaderIfNotNull(request, Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM,
sseKey.getAlgorithm());
addHeaderIfNotNull(request, Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY,
sseKey.getKey());
addHeaderIfNotNull(request, Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
sseKey.getMd5());
// Calculate the MD5 hash of the encryption key and fill it in the
// header, if the user didn't specify it in the metadata
if (sseKey.getKey() != null
&& sseKey.getMd5() == null) {
String encryptionKey_b64 = sseKey.getKey();
byte[] encryptionKey = Base64.decode(encryptionKey_b64);
request.addHeader(Headers.SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
Md5Utils.md5AsBase64(encryptionKey));
}
}
示例2: populateSourceSSE_C
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private static void populateSourceSSE_C(Request<?> request, SSECustomerKey sseKey) {
if (sseKey == null) return;
// Populate the SSE-C parameters for the source object
addHeaderIfNotNull(request, Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_ALGORITHM,
sseKey.getAlgorithm());
addHeaderIfNotNull(request, Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY,
sseKey.getKey());
addHeaderIfNotNull(request, Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
sseKey.getMd5());
// Calculate the MD5 hash of the encryption key and fill it in the
// header, if the user didn't specify it in the metadata
if (sseKey.getKey() != null
&& sseKey.getMd5() == null) {
String encryptionKey_b64 = sseKey.getKey();
byte[] encryptionKey = Base64.decode(encryptionKey_b64);
request.addHeader(Headers.COPY_SOURCE_SERVER_SIDE_ENCRYPTION_CUSTOMER_KEY_MD5,
Md5Utils.md5AsBase64(encryptionKey));
}
}
示例3: correctMD5Test
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Test
public void correctMD5Test() throws Exception {
String payload = "Hello, World";
String messageBody = messageMarshaller.serialize(MessageBuilder
.withPayload(payload).build());
com.amazonaws.services.sqs.model.Message sqsMessage = new com.amazonaws.services.sqs.model.Message();
sqsMessage.setBody(messageBody);
sqsMessage.setMD5OfBody(new String(Hex.encodeHex(Md5Utils
.computeMD5Hash(messageBody.getBytes("UTF-8")))));
ReceiveMessageResult result = new ReceiveMessageResult();
result.setMessages(Collections.singletonList(sqsMessage));
when(mockSQS.receiveMessage(any(ReceiveMessageRequest.class)))
.thenReturn(result);
Message<?> recvMessage = executor.poll();
assertNotNull("message is not null", recvMessage);
Message<?> enclosed = messageMarshaller
.deserialize((String) recvMessage.getPayload());
String recvPayload = (String) enclosed.getPayload();
assertEquals("payload must match", payload, recvPayload);
}
示例4: testUploadManyFiles
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Test
public void testUploadManyFiles() throws Exception {
init("s3.default.properties");
for (int i = 0; i < 8; i++) {
sink.append(new Record(Integer.toString(i), Integer.toString(i).getBytes()));
}
List<String> md5s = new ArrayList<>();
for (String file : sink.getBuffer().getFiles()) {
md5s.add(new String(Md5Utils.md5AsBase64(new File(file))));
}
sink.prepareCommit();
sink.commit();
ObjectListing list = s3.listObjects(s3SinkConfig.getBucketName(), "10");
assertTrue(list.getObjectSummaries().size() == 4);
for (int i = 0; i < 8; i += 2) {
S3Object s3object = s3.getObject(s3SinkConfig.getBucketName(), "10/" + i + "_" + (i + 1));
assertNotNull(s3object);
}
}
示例5: putObject
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Override
public PutObjectResult putObject(String bucketName, String key, File file) throws AmazonClientException,
AmazonServiceException {
throwException(putObjectException);
List<String> keys = files.get(bucketName);
if (keys == null) {
throw new AmazonClientException("Bucket do not exist");
}
keys.add(key);
files.put(bucketName, keys);
PutObjectResult result = new PutObjectResult();
try {
result.setContentMd5(new String(Md5Utils.md5AsBase64(file)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
示例6: getObjectMD5
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private String getObjectMD5(byte[] objectData) {
byte[] expectedMd5 = null;
try {
expectedMd5 = Md5Utils.computeMD5Hash(objectData);
} catch (Exception e) {}
return BinaryUtils.toHex(expectedMd5);
}
示例7: getAwsMessageMD5
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private String getAwsMessageMD5(String message) {
byte[] expectedMd5 = null;
try {
expectedMd5 = Md5Utils.computeMD5Hash(message.getBytes(UTF8));
} catch (Exception e) {}
return BinaryUtils.toHex(expectedMd5);
}
示例8: writeFile
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Override
void writeFile(final String path, final byte[] data) throws IOException {
ObjectMetadata bucketMetadata = new ObjectMetadata();
bucketMetadata.setContentMD5(Md5Utils.md5AsBase64(data));
bucketMetadata.setContentLength(data.length);
// Give Tika a few hints for the content detection
Metadata tikaMetadata = new Metadata();
tikaMetadata.set(Metadata.RESOURCE_NAME_KEY, FilenameUtils.getName(FilenameUtils.normalize(path)));
// Fire!
try (InputStream bis = TikaInputStream.get(data, tikaMetadata)) {
bucketMetadata.setContentType(TIKA_DETECTOR.detect(bis, tikaMetadata).toString());
s3.putObject(bucket, resolveKey(path), bis, bucketMetadata);
}
}
示例9: setBucketCrossOriginConfiguration
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Override
public void setBucketCrossOriginConfiguration(
SetBucketCrossOriginConfigurationRequest setBucketCrossOriginConfigurationRequest) {
setBucketCrossOriginConfigurationRequest = beforeClientExecution(setBucketCrossOriginConfigurationRequest);
rejectNull(setBucketCrossOriginConfigurationRequest,
"The set bucket cross origin configuration request object must be specified.");
String bucketName = setBucketCrossOriginConfigurationRequest.getBucketName();
BucketCrossOriginConfiguration bucketCrossOriginConfiguration = setBucketCrossOriginConfigurationRequest.getCrossOriginConfiguration();
rejectNull(bucketName,
"The bucket name parameter must be specified when setting bucket cross origin configuration.");
rejectNull(bucketCrossOriginConfiguration,
"The cross origin configuration parameter must be specified when setting bucket cross origin configuration.");
Request<SetBucketCrossOriginConfigurationRequest> request = createRequest(bucketName, null, setBucketCrossOriginConfigurationRequest, HttpMethodName.PUT);
request.addParameter("cors", null);
byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketCrossOriginConfiguration);
request.addHeader("Content-Length", String.valueOf(content.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(content));
try {
byte[] md5 = Md5Utils.computeMD5Hash(content);
String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch ( Exception e ) {
throw new SdkClientException("Couldn't compute md5 sum", e);
}
invoke(request, voidResponseHandler, bucketName, null);
}
示例10: setBucketTaggingConfiguration
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Override
public void setBucketTaggingConfiguration(
SetBucketTaggingConfigurationRequest setBucketTaggingConfigurationRequest) {
setBucketTaggingConfigurationRequest = beforeClientExecution(setBucketTaggingConfigurationRequest);
rejectNull(setBucketTaggingConfigurationRequest,
"The set bucket tagging configuration request object must be specified.");
String bucketName = setBucketTaggingConfigurationRequest.getBucketName();
BucketTaggingConfiguration bucketTaggingConfiguration = setBucketTaggingConfigurationRequest.getTaggingConfiguration();
rejectNull(bucketName,
"The bucket name parameter must be specified when setting bucket tagging configuration.");
rejectNull(bucketTaggingConfiguration,
"The tagging configuration parameter must be specified when setting bucket tagging configuration.");
Request<SetBucketTaggingConfigurationRequest> request = createRequest(bucketName, null, setBucketTaggingConfigurationRequest, HttpMethodName.PUT);
request.addParameter("tagging", null);
byte[] content = new BucketConfigurationXmlFactory().convertToXmlByteArray(bucketTaggingConfiguration);
request.addHeader("Content-Length", String.valueOf(content.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(content));
try {
byte[] md5 = Md5Utils.computeMD5Hash(content);
String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch ( Exception e ) {
throw new SdkClientException("Couldn't compute md5 sum", e);
}
invoke(request, voidResponseHandler, bucketName, null);
}
示例11: setContent
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private void setContent(Request<?> request, byte[] content, String contentType, boolean setMd5) {
request.setContent(new ByteArrayInputStream(content));
request.addHeader("Content-Length", Integer.toString(content.length));
request.addHeader("Content-Type", contentType);
if (setMd5) {
try {
byte[] md5 = Md5Utils.computeMD5Hash(content);
String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch ( Exception e ) {
throw new AmazonClientException("Couldn't compute md5 sum", e);
}
}
}
示例12: test
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Test
@Override
public void test() throws Exception {
AmazonS3 amazonS3Client = TestUtils.getPropertyValue(this.s3MessageHandler, "transferManager.s3",
AmazonS3.class);
InputStream payload = new StringInputStream("a");
Message<?> message = MessageBuilder.withPayload(payload)
.setHeader("key", "myInputStream")
.build();
this.channels.input().send(message);
ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor =
ArgumentCaptor.forClass(PutObjectRequest.class);
verify(amazonS3Client, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture());
PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue();
assertThat(putObjectRequest.getBucketName(), equalTo(S3_BUCKET));
assertThat(putObjectRequest.getKey(), equalTo("myInputStream"));
assertNull(putObjectRequest.getFile());
assertNotNull(putObjectRequest.getInputStream());
ObjectMetadata metadata = putObjectRequest.getMetadata();
assertThat(metadata.getContentMD5(), equalTo(Md5Utils.md5AsBase64(payload)));
assertThat(metadata.getContentLength(), equalTo(1L));
assertThat(metadata.getContentType(), equalTo(MediaType.APPLICATION_JSON_VALUE));
assertThat(metadata.getContentDisposition(), equalTo("test.json"));
}
示例13: etag
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private String etag(File file) {
try {
FileInputStream fileInputStream = new FileInputStream(file);
byte[] md5Hash = Md5Utils.computeMD5Hash(fileInputStream);
return BinaryUtils.toHex(md5Hash);
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例14: deleteObjects
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
@Override
public DeleteObjectsResult deleteObjects(DeleteObjectsRequest deleteObjectsRequest) {
deleteObjectsRequest = beforeClientExecution(deleteObjectsRequest);
Request<DeleteObjectsRequest> request = createRequest(deleteObjectsRequest.getBucketName(), null, deleteObjectsRequest, HttpMethodName.POST);
request.addParameter("delete", null);
if ( deleteObjectsRequest.getMfa() != null ) {
populateRequestWithMfaDetails(request, deleteObjectsRequest.getMfa());
}
populateRequesterPaysHeader(request, deleteObjectsRequest.isRequesterPays());
byte[] content = new MultiObjectDeleteXmlFactory().convertToXmlByteArray(deleteObjectsRequest);
request.addHeader("Content-Length", String.valueOf(content.length));
request.addHeader("Content-Type", "application/xml");
request.setContent(new ByteArrayInputStream(content));
try {
byte[] md5 = Md5Utils.computeMD5Hash(content);
String md5Base64 = BinaryUtils.toBase64(md5);
request.addHeader("Content-MD5", md5Base64);
} catch ( Exception e ) {
throw new SdkClientException("Couldn't compute md5 sum", e);
}
@SuppressWarnings("unchecked")
ResponseHeaderHandlerChain<DeleteObjectsResponse> responseHandler = new ResponseHeaderHandlerChain<DeleteObjectsResponse>(
new Unmarshallers.DeleteObjectsResultUnmarshaller(),
new S3RequesterChargedHeaderHandler<DeleteObjectsResponse>());
DeleteObjectsResponse response = invoke(request, responseHandler, deleteObjectsRequest.getBucketName(), null);
/*
* If the result was only partially successful, throw an exception
*/
if ( !response.getErrors().isEmpty() ) {
Map<String, String> headers = responseHandler.getResponseHeaders();
MultiObjectDeleteException ex = new MultiObjectDeleteException(
response.getErrors(),
response.getDeletedObjects());
ex.setStatusCode(200);
ex.setRequestId(headers.get(Headers.REQUEST_ID));
ex.setExtendedRequestId(headers.get(Headers.EXTENDED_REQUEST_ID));
ex.setCloudFrontId(headers.get(Headers.CLOUD_FRONT_ID));
throw ex;
}
DeleteObjectsResult result = new DeleteObjectsResult(response.getDeletedObjects(), response.isRequesterCharged());
return result;
}
示例15: getMD5
import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private String getMD5(byte[] bytes) {
return BinaryUtils.toHex(Md5Utils.computeMD5Hash(bytes));
}