com.amazonaws.util.BinaryUtils Java Examples
The following examples show how to use
com.amazonaws.util.BinaryUtils.
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 File: SimpleStorageResource.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
private void finishSimpleUpload() { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(this.currentOutputStream.size()); byte[] content = this.currentOutputStream.toByteArray(); try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); String md5Digest = BinaryUtils.toBase64(messageDigest.digest(content)); objectMetadata.setContentMD5(md5Digest); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "MessageDigest could not be initialized because it uses an unknown algorithm", e); } SimpleStorageResource.this.amazonS3.putObject( SimpleStorageResource.this.bucketName, SimpleStorageResource.this.objectName, new ByteArrayInputStream(content), objectMetadata); // Release the memory early this.currentOutputStream = null; }
Example #2
Source File: SQSExecutorService.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
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))); } messageContent.setMessageAttributesEntry(SQSFutureTask.DEDUPLICATION_ID_ATTRIBUTE_NAME, stringMessageAttributeValue(deduplicationID)); } messageContent.setMessageAttributesEntry(SQSFutureTask.UUID_ATTRIBUTE_NAME, stringMessageAttributeValue(UUID.randomUUID().toString())); }
Example #3
Source File: S3ScanWriter.java From emodb with Apache License 2.0 | 5 votes |
private void uploadContents(String bucket, String key, byte[] contents) throws IOException { int failures = 0; boolean uploaded = false; while (!uploaded) { ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentType(MediaType.TEXT_PLAIN); objectMetadata.setContentLength(contents.length); objectMetadata.setContentMD5(BinaryUtils.toBase64(Hashing.md5().hashBytes(contents).asBytes())); try { _amazonS3.putObject( new PutObjectRequest(bucket, key, new ByteArrayInputStream(contents), objectMetadata)); uploaded = true; } catch (AmazonClientException e) { if (++failures == MAX_RETRIES) { throw new IOException(e); } try { Thread.sleep(_retryDelay.toMillis()); } catch (InterruptedException e2) { // Stop retrying and propagate the original exception throw new IOException(e); } } } }
Example #4
Source File: StreamTransferManager.java From s3-stream-upload with MIT License | 5 votes |
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) { md.update(BinaryUtils.fromHex(partETag.getETag())); } // 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()); }