Java Code Examples for com.amazonaws.util.BinaryUtils

The following examples show how to use com.amazonaws.util.BinaryUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-cloud-aws   Source File:    License: Apache License 2.0 6 votes vote down vote up
private void finishSimpleUpload() {
	ObjectMetadata objectMetadata = new ObjectMetadata();

	byte[] content = this.currentOutputStream.toByteArray();
	try {
		MessageDigest messageDigest = MessageDigest.getInstance("MD5");
		String md5Digest = BinaryUtils.toBase64(messageDigest.digest(content));
	catch (NoSuchAlgorithmException e) {
		throw new IllegalStateException(
				"MessageDigest could not be initialized because it uses an unknown algorithm",

			new ByteArrayInputStream(content), objectMetadata);

	// Release the memory early
	this.currentOutputStream = null;
Example 2
private void addDeduplicationAttributes(MessageContent messageContent, Object task) {
    if (task instanceof Deduplicated) {
        String deduplicationID = ((Deduplicated)task).deduplicationID();
        if (deduplicationID == null) {
            String body = messageContent.getMessageBody();
            deduplicationID = BinaryUtils.toHex(Md5Utils.computeMD5Hash(body.getBytes(UTF8)));
Example 3
Source Project: emodb   Source File:    License: Apache License 2.0 5 votes vote down vote up
private void uploadContents(String bucket, String key, byte[] contents)
        throws IOException {
    int failures = 0;
    boolean uploaded = false;
    while (!uploaded) {
        ObjectMetadata objectMetadata = new ObjectMetadata();

        try {
                    new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), objectMetadata));
            uploaded = true;
        } catch (AmazonClientException e) {
            if (++failures == MAX_RETRIES) {
                throw new IOException(e);
            try {
            } catch (InterruptedException e2) {
                // Stop retrying and propagate the original exception
                throw new IOException(e);
Example 4
Source Project: s3-stream-upload   Source File:    License: MIT License 5 votes vote down vote up
private String computeCompleteFileETag(List<PartETag> parts) {
    // When S3 combines the parts of a multipart upload into the final object, the ETag value is set to the
    // hex-encoded MD5 hash of the concatenated binary-encoded (raw bytes) MD5 hashes of each part followed by
    // "-" and the number of parts.
    MessageDigest md = Utils.md5();
    for (PartETag partETag : parts) {
    // Represent byte array as a 32-digit number hexadecimal format followed by "-<partCount>".
    return String.format("%032x-%d", new BigInteger(1, md.digest()), parts.size());