18
18
import java .io .File ;
19
19
import java .nio .file .Path ;
20
20
import java .util .Objects ;
21
+ import java .util .Optional ;
21
22
import java .util .function .Consumer ;
22
23
import software .amazon .awssdk .annotations .NotThreadSafe ;
23
24
import software .amazon .awssdk .annotations .SdkPreviewApi ;
24
25
import software .amazon .awssdk .annotations .SdkPublicApi ;
25
26
import software .amazon .awssdk .services .s3 .model .GetObjectRequest ;
27
+ import software .amazon .awssdk .utils .ToString ;
26
28
import software .amazon .awssdk .utils .Validate ;
27
29
import software .amazon .awssdk .utils .builder .CopyableBuilder ;
28
30
import software .amazon .awssdk .utils .builder .ToCopyableBuilder ;
35
37
public final class DownloadRequest implements TransferRequest , ToCopyableBuilder <DownloadRequest .Builder , DownloadRequest > {
36
38
private final Path destination ;
37
39
private final GetObjectRequest getObjectRequest ;
40
+ private final TransferRequestOverrideConfiguration overrideConfiguration ;
38
41
39
42
private DownloadRequest (BuilderImpl builder ) {
40
43
this .destination = Validate .paramNotNull (builder .destination , "destination" );
41
44
this .getObjectRequest = Validate .paramNotNull (builder .getObjectRequest , "getObjectRequest" );
45
+ this .overrideConfiguration = builder .configuration ;
42
46
}
43
47
44
48
/**
@@ -72,6 +76,23 @@ public GetObjectRequest getObjectRequest() {
72
76
return getObjectRequest ;
73
77
}
74
78
79
+ /**
80
+ * @return the optional override configuration
81
+ * @see Builder#overrideConfiguration(TransferRequestOverrideConfiguration)
82
+ */
83
+ public Optional <TransferRequestOverrideConfiguration > overrideConfiguration () {
84
+ return Optional .ofNullable (overrideConfiguration );
85
+ }
86
+
87
+ @ Override
88
+ public String toString () {
89
+ return ToString .builder ("DownloadRequest" )
90
+ .add ("destination" , destination )
91
+ .add ("getObjectRequest" , getObjectRequest )
92
+ .add ("overrideConfiguration" , overrideConfiguration )
93
+ .build ();
94
+ }
95
+
75
96
@ Override
76
97
public boolean equals (Object o ) {
77
98
if (this == o ) {
@@ -86,13 +107,17 @@ public boolean equals(Object o) {
86
107
if (!Objects .equals (destination , that .destination )) {
87
108
return false ;
88
109
}
89
- return Objects .equals (getObjectRequest , that .getObjectRequest );
110
+ if (!Objects .equals (getObjectRequest , that .getObjectRequest )) {
111
+ return false ;
112
+ }
113
+ return Objects .equals (overrideConfiguration , that .overrideConfiguration );
90
114
}
91
115
92
116
@ Override
93
117
public int hashCode () {
94
118
int result = destination != null ? destination .hashCode () : 0 ;
95
119
result = 31 * result + (getObjectRequest != null ? getObjectRequest .hashCode () : 0 );
120
+ result = 31 * result + (overrideConfiguration != null ? overrideConfiguration .hashCode () : 0 );
96
121
return result ;
97
122
}
98
123
@@ -157,6 +182,31 @@ default Builder getObjectRequest(Consumer<GetObjectRequest.Builder> getObjectReq
157
182
return this ;
158
183
}
159
184
185
+ /**
186
+ * Add an optional request override configuration.
187
+ *
188
+ * @param configuration The override configuration.
189
+ * @return This builder for method chaining.
190
+ */
191
+ Builder overrideConfiguration (TransferRequestOverrideConfiguration configuration );
192
+
193
+ /**
194
+ * Similar to {@link #overrideConfiguration(TransferRequestOverrideConfiguration)}, but takes a lambda to configure a new
195
+ * {@link TransferRequestOverrideConfiguration.Builder}. This removes the need to call
196
+ * {@link TransferRequestOverrideConfiguration#builder()} and
197
+ * {@link TransferRequestOverrideConfiguration.Builder#build()}.
198
+ *
199
+ * @param configurationBuilder the upload configuration
200
+ * @return this builder for method chaining.
201
+ * @see #overrideConfiguration(TransferRequestOverrideConfiguration)
202
+ */
203
+ default Builder overrideConfiguration (Consumer <TransferRequestOverrideConfiguration .Builder > configurationBuilder ) {
204
+ Validate .paramNotNull (configurationBuilder , "configurationBuilder" );
205
+ return overrideConfiguration (TransferRequestOverrideConfiguration .builder ()
206
+ .applyMutation (configurationBuilder )
207
+ .build ());
208
+ }
209
+
160
210
/**
161
211
* @return The built request.
162
212
*/
@@ -167,6 +217,7 @@ default Builder getObjectRequest(Consumer<GetObjectRequest.Builder> getObjectReq
167
217
private static final class BuilderImpl implements Builder {
168
218
private Path destination ;
169
219
private GetObjectRequest getObjectRequest ;
220
+ private TransferRequestOverrideConfiguration configuration ;
170
221
171
222
private BuilderImpl () {
172
223
}
@@ -199,6 +250,20 @@ public void setGetObjectRequest(GetObjectRequest getObjectRequest) {
199
250
getObjectRequest (getObjectRequest );
200
251
}
201
252
253
+ @ Override
254
+ public Builder overrideConfiguration (TransferRequestOverrideConfiguration configuration ) {
255
+ this .configuration = configuration ;
256
+ return this ;
257
+ }
258
+
259
+ public void setOverrideConfiguration (TransferRequestOverrideConfiguration configuration ) {
260
+ overrideConfiguration (configuration );
261
+ }
262
+
263
+ public TransferRequestOverrideConfiguration getOverrideConfiguration () {
264
+ return configuration ;
265
+ }
266
+
202
267
@ Override
203
268
public DownloadRequest build () {
204
269
return new DownloadRequest (this );
0 commit comments