@Override public PutObjectResponse build() { return new PutObjectResponse(this); }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("PutObjectResponse").add("Expiration", expiration()).add("ETag", eTag()) .add("ServerSideEncryption", serverSideEncryptionAsString()).add("VersionId", versionId()) .add("SSECustomerAlgorithm", sseCustomerAlgorithm()).add("SSECustomerKeyMD5", sseCustomerKeyMD5()) .add("SSEKMSKeyId", ssekmsKeyId() == null ? null : "*** Sensitive Data Redacted ***") .add("RequestCharged", requestChargedAsString()).build(); }
public void upload(final String bucketName, final File file) { final PutObjectResponse putObjectResponse = s3Client.putObject(PutObjectRequest.builder() .bucket(bucketName) .key(file.getName()) .build(), file.toPath()); LOG.debug("upload {} to bucket {}: ", file.getName(), bucketName, putObjectResponse.toString()); }
@Override public PutObjectResponse putObject(final PutObjectRequest putObjectRequest, final RequestBody requestBody) throws S3Exception { try { bucketsWithContents.get(putObjectRequest.bucket()).put(putObjectRequest.key(), bucketItemBuilder() .withName(putObjectRequest.key()) .withData(toByteArray(requestBody.contentStreamProvider().newStream())) .withLastModifiedNow() .build()); return PutObjectResponse.builder().build(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Client side validation for {@link PutObjectRequest} * * @param response the response * @param executionAttributes the execution attributes */ public static void validatePutObjectChecksum(PutObjectResponse response, ExecutionAttributes executionAttributes) { SdkChecksum checksum = executionAttributes.getAttribute(CHECKSUM); if (response.eTag() != null) { String contentMd5 = BinaryUtils.toBase64(checksum.getChecksumBytes()); byte[] digest = BinaryUtils.fromBase64(contentMd5); byte[] ssHash = Base16Lower.decode(response.eTag().replace("\"", "")); if (!Arrays.equals(digest, ssHash)) { throw SdkClientException.create("Data read has a different checksum than expected."); } } }
@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(expiration()); hashCode = 31 * hashCode + Objects.hashCode(eTag()); hashCode = 31 * hashCode + Objects.hashCode(serverSideEncryptionAsString()); hashCode = 31 * hashCode + Objects.hashCode(versionId()); hashCode = 31 * hashCode + Objects.hashCode(sseCustomerAlgorithm()); hashCode = 31 * hashCode + Objects.hashCode(sseCustomerKeyMD5()); hashCode = 31 * hashCode + Objects.hashCode(ssekmsKeyId()); hashCode = 31 * hashCode + Objects.hashCode(requestChargedAsString()); return hashCode; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof PutObjectResponse)) { return false; } PutObjectResponse other = (PutObjectResponse) obj; return Objects.equals(expiration(), other.expiration()) && Objects.equals(eTag(), other.eTag()) && Objects.equals(serverSideEncryptionAsString(), other.serverSideEncryptionAsString()) && Objects.equals(versionId(), other.versionId()) && Objects.equals(sseCustomerAlgorithm(), other.sseCustomerAlgorithm()) && Objects.equals(sseCustomerKeyMD5(), other.sseCustomerKeyMD5()) && Objects.equals(ssekmsKeyId(), other.ssekmsKeyId()) && Objects.equals(requestChargedAsString(), other.requestChargedAsString()); }
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "Expiration": return Optional.ofNullable(clazz.cast(expiration())); case "ETag": return Optional.ofNullable(clazz.cast(eTag())); case "ServerSideEncryption": return Optional.ofNullable(clazz.cast(serverSideEncryptionAsString())); case "VersionId": return Optional.ofNullable(clazz.cast(versionId())); case "SSECustomerAlgorithm": return Optional.ofNullable(clazz.cast(sseCustomerAlgorithm())); case "SSECustomerKeyMD5": return Optional.ofNullable(clazz.cast(sseCustomerKeyMD5())); case "SSEKMSKeyId": return Optional.ofNullable(clazz.cast(ssekmsKeyId())); case "RequestCharged": return Optional.ofNullable(clazz.cast(requestChargedAsString())); default: return Optional.empty(); } }