@Override public GetObjectResponse build() { return new GetObjectResponse(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("GetObjectResponse").add("DeleteMarker", deleteMarker()).add("AcceptRanges", acceptRanges()) .add("Expiration", expiration()).add("Restore", restore()).add("LastModified", lastModified()) .add("ContentLength", contentLength()).add("ETag", eTag()).add("MissingMeta", missingMeta()) .add("VersionId", versionId()).add("CacheControl", cacheControl()) .add("ContentDisposition", contentDisposition()).add("ContentEncoding", contentEncoding()) .add("ContentLanguage", contentLanguage()).add("ContentRange", contentRange()).add("ContentType", contentType()) .add("Expires", expires()).add("WebsiteRedirectLocation", websiteRedirectLocation()) .add("ServerSideEncryption", serverSideEncryptionAsString()).add("Metadata", metadata()) .add("SSECustomerAlgorithm", sseCustomerAlgorithm()).add("SSECustomerKeyMD5", sseCustomerKeyMD5()) .add("SSEKMSKeyId", ssekmsKeyId() == null ? null : "*** Sensitive Data Redacted ***") .add("StorageClass", storageClassAsString()).add("RequestCharged", requestChargedAsString()) .add("ReplicationStatus", replicationStatusAsString()).add("PartsCount", partsCount()) .add("TagCount", tagCount()).add("ObjectLockMode", objectLockModeAsString()) .add("ObjectLockRetainUntilDate", objectLockRetainUntilDate()) .add("ObjectLockLegalHoldStatus", objectLockLegalHoldStatusAsString()).build(); }
@Override public GetObjectResponse getObject(final GetObjectRequest getObjectRequest, final Path filePath) throws S3Exception { final Map<String, BucketItem> bucketItemMap = bucketsWithContents.get(getObjectRequest.bucket()); final BucketItem bucketItem = bucketItemMap.get(getObjectRequest.key()); try { Files.write(filePath, bucketItem.getData()); } catch (IOException e) { throw SdkClientException.create("", e); } return GetObjectResponse.builder().build(); }
/** * Subtract the contentLength of {@link GetObjectResponse} if trailing checksums is enabled. */ @Override public SdkResponse modifyResponse(Context.ModifyResponse context, ExecutionAttributes executionAttributes) { SdkResponse response = context.response(); SdkHttpResponse httpResponse = context.httpResponse(); if (getObjectChecksumEnabledPerResponse(context.request(), httpResponse)) { GetObjectResponse getResponse = (GetObjectResponse) response; return getResponse.toBuilder().contentLength(getResponse.contentLength() - S3_MD5_CHECKSUM_LENGTH).build(); } return response; } }
@SuppressWarnings("unchecked") @Override public ResponseInputStream<GetObjectResponse> getObject(final GetObjectRequest getObjectRequest) throws S3Exception { final Map<String, BucketItem> bucketItemMap = bucketsWithContents.get(getObjectRequest.bucket()); final BucketItem bucketItem = bucketItemMap.get(getObjectRequest.key()); if (bucketItem != null) { try { return new ResponseInputStream<>(GetObjectResponse.builder().build(), toAbortableInputStream(bucketItem)); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { throw SdkClientException.create("", e); } } else { throw NoSuchKeyException.builder().message("NoSuchKey").awsErrorDetails(AwsErrorDetails.builder().errorCode("NoSuchKey").build()).build(); } }
return Objects.equals(deleteMarker(), other.deleteMarker()) && Objects.equals(acceptRanges(), other.acceptRanges()) && Objects.equals(expiration(), other.expiration()) && Objects.equals(restore(), other.restore()) && Objects.equals(lastModified(), other.lastModified()) && Objects.equals(contentLength(), other.contentLength()) && Objects.equals(eTag(), other.eTag()) && Objects.equals(missingMeta(), other.missingMeta()) && Objects.equals(versionId(), other.versionId()) && Objects.equals(cacheControl(), other.cacheControl()) && Objects.equals(contentDisposition(), other.contentDisposition()) && Objects.equals(contentEncoding(), other.contentEncoding()) && Objects.equals(contentLanguage(), other.contentLanguage()) && Objects.equals(contentRange(), other.contentRange()) && Objects.equals(contentType(), other.contentType()) && Objects.equals(expires(), other.expires()) && Objects.equals(websiteRedirectLocation(), other.websiteRedirectLocation()) && Objects.equals(serverSideEncryptionAsString(), other.serverSideEncryptionAsString()) && Objects.equals(metadata(), other.metadata()) && Objects.equals(sseCustomerAlgorithm(), other.sseCustomerAlgorithm()) && Objects.equals(sseCustomerKeyMD5(), other.sseCustomerKeyMD5()) && Objects.equals(ssekmsKeyId(), other.ssekmsKeyId()) && Objects.equals(storageClassAsString(), other.storageClassAsString()) && Objects.equals(requestChargedAsString(), other.requestChargedAsString()) && Objects.equals(replicationStatusAsString(), other.replicationStatusAsString()) && Objects.equals(partsCount(), other.partsCount()) && Objects.equals(tagCount(), other.tagCount()) && Objects.equals(objectLockModeAsString(), other.objectLockModeAsString()) && Objects.equals(objectLockRetainUntilDate(), other.objectLockRetainUntilDate()) && Objects.equals(objectLockLegalHoldStatusAsString(), other.objectLockLegalHoldStatusAsString());
@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(deleteMarker()); hashCode = 31 * hashCode + Objects.hashCode(acceptRanges()); hashCode = 31 * hashCode + Objects.hashCode(expiration()); hashCode = 31 * hashCode + Objects.hashCode(restore()); hashCode = 31 * hashCode + Objects.hashCode(lastModified()); hashCode = 31 * hashCode + Objects.hashCode(contentLength()); hashCode = 31 * hashCode + Objects.hashCode(eTag()); hashCode = 31 * hashCode + Objects.hashCode(missingMeta()); hashCode = 31 * hashCode + Objects.hashCode(versionId()); hashCode = 31 * hashCode + Objects.hashCode(cacheControl()); hashCode = 31 * hashCode + Objects.hashCode(contentDisposition()); hashCode = 31 * hashCode + Objects.hashCode(contentEncoding()); hashCode = 31 * hashCode + Objects.hashCode(contentLanguage()); hashCode = 31 * hashCode + Objects.hashCode(contentRange()); hashCode = 31 * hashCode + Objects.hashCode(contentType()); hashCode = 31 * hashCode + Objects.hashCode(expires()); hashCode = 31 * hashCode + Objects.hashCode(websiteRedirectLocation()); hashCode = 31 * hashCode + Objects.hashCode(serverSideEncryptionAsString()); hashCode = 31 * hashCode + Objects.hashCode(metadata()); hashCode = 31 * hashCode + Objects.hashCode(sseCustomerAlgorithm()); hashCode = 31 * hashCode + Objects.hashCode(sseCustomerKeyMD5()); hashCode = 31 * hashCode + Objects.hashCode(ssekmsKeyId()); hashCode = 31 * hashCode + Objects.hashCode(storageClassAsString()); hashCode = 31 * hashCode + Objects.hashCode(requestChargedAsString()); hashCode = 31 * hashCode + Objects.hashCode(replicationStatusAsString()); hashCode = 31 * hashCode + Objects.hashCode(partsCount()); hashCode = 31 * hashCode + Objects.hashCode(tagCount());
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "DeleteMarker": return Optional.ofNullable(clazz.cast(deleteMarker())); case "AcceptRanges": return Optional.ofNullable(clazz.cast(acceptRanges())); case "Expiration": return Optional.ofNullable(clazz.cast(expiration())); case "Restore": return Optional.ofNullable(clazz.cast(restore())); case "LastModified": return Optional.ofNullable(clazz.cast(lastModified())); case "ContentLength": return Optional.ofNullable(clazz.cast(contentLength())); case "ETag": return Optional.ofNullable(clazz.cast(eTag())); case "MissingMeta": return Optional.ofNullable(clazz.cast(missingMeta())); case "VersionId": return Optional.ofNullable(clazz.cast(versionId())); case "CacheControl": return Optional.ofNullable(clazz.cast(cacheControl())); case "ContentDisposition": return Optional.ofNullable(clazz.cast(contentDisposition())); case "ContentEncoding": return Optional.ofNullable(clazz.cast(contentEncoding())); case "ContentLanguage": return Optional.ofNullable(clazz.cast(contentLanguage())); case "ContentRange": return Optional.ofNullable(clazz.cast(contentRange()));