|
17 | 17 |
|
18 | 18 | import software.amazon.awssdk.annotations.SdkPreviewApi;
|
19 | 19 | import software.amazon.awssdk.annotations.SdkPublicApi;
|
| 20 | +import software.amazon.awssdk.services.s3.S3AsyncClient; |
20 | 21 | import software.amazon.awssdk.services.s3.model.PutObjectResponse;
|
| 22 | +import software.amazon.awssdk.utils.ToString; |
| 23 | +import software.amazon.awssdk.utils.Validate; |
21 | 24 |
|
22 | 25 | /**
|
23 |
| - * A completed upload transfer. |
| 26 | + * Represents a completed upload transfer to Amazon S3. It can be used to track |
| 27 | + * the underlying {@link PutObjectResponse} |
| 28 | + * |
| 29 | + * @see S3TransferManager#upload(UploadRequest) |
24 | 30 | */
|
25 | 31 | @SdkPublicApi
|
26 | 32 | @SdkPreviewApi
|
27 |
| -public interface CompletedUpload extends CompletedTransfer { |
| 33 | +public final class CompletedUpload implements CompletedTransfer { |
| 34 | + private final PutObjectResponse response; |
| 35 | + |
| 36 | + private CompletedUpload(DefaultBuilder builder) { |
| 37 | + this.response = Validate.paramNotNull(builder.response, "response"); |
| 38 | + } |
28 | 39 |
|
29 | 40 | /**
|
30 | 41 | * Returns the API response from the {@link S3TransferManager#upload(UploadRequest)}
|
31 | 42 | * @return the response
|
32 | 43 | */
|
33 |
| - PutObjectResponse response(); |
| 44 | + public PutObjectResponse response() { |
| 45 | + return response; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public boolean equals(Object o) { |
| 50 | + if (this == o) { |
| 51 | + return true; |
| 52 | + } |
| 53 | + if (o == null || getClass() != o.getClass()) { |
| 54 | + return false; |
| 55 | + } |
| 56 | + |
| 57 | + CompletedUpload that = (CompletedUpload) o; |
| 58 | + |
| 59 | + return response.equals(that.response); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public int hashCode() { |
| 64 | + return response.hashCode(); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public String toString() { |
| 69 | + return ToString.builder("CompletedUpload") |
| 70 | + .add("response", response) |
| 71 | + .build(); |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Creates a default builder for {@link CompletedUpload}. |
| 76 | + */ |
| 77 | + public static Builder builder() { |
| 78 | + return new DefaultBuilder(); |
| 79 | + } |
| 80 | + |
| 81 | + public interface Builder { |
| 82 | + /** |
| 83 | + * Specify the {@link PutObjectResponse} from {@link S3AsyncClient#putObject} |
| 84 | + * |
| 85 | + * @param response the response |
| 86 | + * @return This builder for method chaining. |
| 87 | + */ |
| 88 | + Builder response(PutObjectResponse response); |
| 89 | + |
| 90 | + /** |
| 91 | + * Builds a {@link CompletedUpload} based on the properties supplied to this builder |
| 92 | + * @return An initialized {@link CompletedUpload} |
| 93 | + */ |
| 94 | + CompletedUpload build(); |
| 95 | + } |
| 96 | + |
| 97 | + private static class DefaultBuilder implements Builder { |
| 98 | + private PutObjectResponse response; |
| 99 | + |
| 100 | + private DefaultBuilder() { |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public Builder response(PutObjectResponse response) { |
| 105 | + this.response = response; |
| 106 | + return this; |
| 107 | + } |
| 108 | + |
| 109 | + @Override |
| 110 | + public CompletedUpload build() { |
| 111 | + return new CompletedUpload(this); |
| 112 | + } |
| 113 | + } |
34 | 114 | }
|
0 commit comments