|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +package software.amazon.awssdk.services.s3.internal.presignedurl.model; |
| 17 | + |
| 18 | +import java.net.URL; |
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.Collections; |
| 21 | +import java.util.HashMap; |
| 22 | +import java.util.List; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.Objects; |
| 25 | +import java.util.function.Function; |
| 26 | +import software.amazon.awssdk.annotations.SdkInternalApi; |
| 27 | +import software.amazon.awssdk.core.SdkField; |
| 28 | +import software.amazon.awssdk.core.protocol.MarshallLocation; |
| 29 | +import software.amazon.awssdk.core.protocol.MarshallingType; |
| 30 | +import software.amazon.awssdk.core.traits.LocationTrait; |
| 31 | +import software.amazon.awssdk.services.s3.model.S3Request; |
| 32 | + |
| 33 | +/** |
| 34 | + * Internal request object for presigned URL GetObject operations. |
| 35 | + * <p> |
| 36 | + * This class is used internally by the AWS SDK to process presigned URL requests for S3 GetObject operations. It contains minimal |
| 37 | + * SdkField definitions needed for custom marshalling and is not intended for direct use by SDK users. |
| 38 | + * </p> |
| 39 | + * <b>Note:</b> This is an internal implementation class and should not be used |
| 40 | + * directly. Use {@code PresignedUrlGetObjectRequest} for public API interactions. |
| 41 | + */ |
| 42 | +@SdkInternalApi |
| 43 | +public final class PresignedUrlGetObjectRequestWrapper extends S3Request { |
| 44 | + private static final SdkField<String> RANGE_FIELD = SdkField |
| 45 | + .<String>builder(MarshallingType.STRING) |
| 46 | + .memberName("Range") |
| 47 | + .getter(getter(PresignedUrlGetObjectRequestWrapper::range)) |
| 48 | + .traits(LocationTrait.builder().location(MarshallLocation.HEADER).locationName("Range") |
| 49 | + .unmarshallLocationName("Range").build()).build(); |
| 50 | + |
| 51 | + private static final List<SdkField<?>> SDK_FIELDS = Collections.unmodifiableList( |
| 52 | + Arrays.asList(RANGE_FIELD)); |
| 53 | + |
| 54 | + private static final Map<String, SdkField<?>> SDK_NAME_TO_FIELD = memberNameToFieldInitializer(); |
| 55 | + |
| 56 | + private final URL url; |
| 57 | + private final String range; |
| 58 | + |
| 59 | + private PresignedUrlGetObjectRequestWrapper(Builder builder) { |
| 60 | + super(builder); |
| 61 | + this.url = builder.url; |
| 62 | + this.range = builder.range; |
| 63 | + } |
| 64 | + |
| 65 | + public URL url() { |
| 66 | + return url; |
| 67 | + } |
| 68 | + |
| 69 | + public String range() { |
| 70 | + return range; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public List<SdkField<?>> sdkFields() { |
| 75 | + return SDK_FIELDS; |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public Map<String, SdkField<?>> sdkFieldNameToField() { |
| 80 | + return SDK_NAME_TO_FIELD; |
| 81 | + } |
| 82 | + |
| 83 | + private static <T> Function<Object, T> getter(Function<PresignedUrlGetObjectRequestWrapper, T> g) { |
| 84 | + return obj -> g.apply((PresignedUrlGetObjectRequestWrapper) obj); |
| 85 | + } |
| 86 | + |
| 87 | + private static Map<String, SdkField<?>> memberNameToFieldInitializer() { |
| 88 | + Map<String, SdkField<?>> map = new HashMap<>(); |
| 89 | + map.put("Range", RANGE_FIELD); |
| 90 | + return Collections.unmodifiableMap(map); |
| 91 | + } |
| 92 | + |
| 93 | + @Override |
| 94 | + public Builder toBuilder() { |
| 95 | + return new Builder(this); |
| 96 | + } |
| 97 | + |
| 98 | + public static Builder builder() { |
| 99 | + return new Builder(); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public boolean equals(Object obj) { |
| 104 | + if (this == obj) { |
| 105 | + return true; |
| 106 | + } |
| 107 | + if (obj == null || getClass() != obj.getClass()) { |
| 108 | + return false; |
| 109 | + } |
| 110 | + if (!super.equals(obj)) { |
| 111 | + return false; |
| 112 | + } |
| 113 | + PresignedUrlGetObjectRequestWrapper that = (PresignedUrlGetObjectRequestWrapper) obj; |
| 114 | + return Objects.equals(url, that.url) && Objects.equals(range, that.range); |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public int hashCode() { |
| 119 | + int result = Objects.hashCode(super.hashCode()); |
| 120 | + result = 31 * result + Objects.hashCode(url); |
| 121 | + result = 31 * result + Objects.hashCode(range); |
| 122 | + return result; |
| 123 | + } |
| 124 | + |
| 125 | + public static final class Builder extends S3Request.BuilderImpl { |
| 126 | + private URL url; |
| 127 | + private String range; |
| 128 | + |
| 129 | + public Builder() { |
| 130 | + } |
| 131 | + |
| 132 | + Builder(PresignedUrlGetObjectRequestWrapper request) { |
| 133 | + super(request); |
| 134 | + this.url = request.url(); |
| 135 | + this.range = request.range(); |
| 136 | + } |
| 137 | + |
| 138 | + public Builder url(URL url) { |
| 139 | + this.url = url; |
| 140 | + return this; |
| 141 | + } |
| 142 | + |
| 143 | + public Builder range(String range) { |
| 144 | + this.range = range; |
| 145 | + return this; |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public PresignedUrlGetObjectRequestWrapper build() { |
| 150 | + return new PresignedUrlGetObjectRequestWrapper(this); |
| 151 | + } |
| 152 | + } |
| 153 | +} |
0 commit comments