• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Md5Utils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.amazonaws.util.Md5Utils的典型用法代码示例。如果您正苦于以下问题:Java Md5Utils类的具体用法?Java Md5Utils怎么用?Java Md5Utils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Md5Utils类属于com.amazonaws.util包,在下文中一共展示了Md5Utils类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:35,代码来源:AmazonS3Client.java


示例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));
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:21,代码来源:AmazonS3Client.java


示例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);
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:25,代码来源:SqsExecutorTest.java


示例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);
  }
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:21,代码来源:S3SinkStreamWriterUnitTest.java


示例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;
}
 
开发者ID:DemandCube,项目名称:Scribengin,代码行数:21,代码来源:AmazonS3Mock.java


示例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);
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:8,代码来源:MockS3Test.java


示例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);
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:8,代码来源:MockSqsTest.java


示例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);
    }
}
 
开发者ID:berlam,项目名称:github-bucket,代码行数:15,代码来源:TransportAmazonLambdaS3.java


示例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);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:33,代码来源:AmazonS3Client.java


示例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);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:33,代码来源:AmazonS3Client.java


示例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);
        }
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:15,代码来源:AmazonS3Client.java


示例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"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:30,代码来源:AmazonS3SinkMockTests.java


示例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);
    }
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:10,代码来源:S3.java


示例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;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:53,代码来源:AmazonS3Client.java


示例15: getMD5

import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
private String getMD5(byte[] bytes) {
    return BinaryUtils.toHex(Md5Utils.computeMD5Hash(bytes));
}
 
开发者ID:bazaarvoice,项目名称:awslocal,代码行数:4,代码来源:DirectorySQSQueue.java


示例16: getMD5

import com.amazonaws.util.Md5Utils; //导入依赖的package包/类
/**
 * Calculates the MD5 hex code of a string (using the util class<br>
 * that the AWS SDK uses for MD5 calculation).
 * 
 * @param message Any text
 * @return Upper-case MD5 checksum in HEX string format
 */
public String getMD5(String message) {
  byte[] expectedMd5 = Md5Utils.computeMD5Hash(message.getBytes(UTF8));
  return BinaryUtils.toHex(expectedMd5);
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:12,代码来源:MessageUtils.java



注:本文中的com.amazonaws.util.Md5Utils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AssociationType类代码示例发布时间:2022-05-22
下一篇:
Java ActivityContentVideoViewClient类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap