forked from aws/aws-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonS3Client.java
More file actions
3106 lines (2697 loc) · 149 KB
/
AmazonS3Client.java
File metadata and controls
3106 lines (2697 loc) · 149 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.services.s3;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.AmazonServiceException.ErrorType;
import com.amazonaws.AmazonWebServiceClient;
import com.amazonaws.AmazonWebServiceRequest;
import com.amazonaws.AmazonWebServiceResponse;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.DefaultRequest;
import com.amazonaws.HttpMethod;
import com.amazonaws.Request;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSCredentialsProviderChain;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.EnvironmentVariableCredentialsProvider;
import com.amazonaws.auth.InstanceProfileCredentialsProvider;
import com.amazonaws.auth.Signer;
import com.amazonaws.auth.SystemPropertiesCredentialsProvider;
import com.amazonaws.event.ProgressListenerCallbackExecutor;
import com.amazonaws.event.ProgressReportingInputStream;
import com.amazonaws.event.ProgressListener;
import com.amazonaws.event.ProgressEvent;
import com.amazonaws.handlers.HandlerChainFactory;
import com.amazonaws.handlers.RequestHandler;
import com.amazonaws.http.ExecutionContext;
import com.amazonaws.http.HttpMethodName;
import com.amazonaws.http.HttpResponseHandler;
import com.amazonaws.internal.StaticCredentialsProvider;
import com.amazonaws.regions.RegionUtils;
import com.amazonaws.services.s3.internal.BucketNameUtils;
import com.amazonaws.services.s3.internal.Constants;
import com.amazonaws.services.s3.internal.DeleteObjectsResponse;
import com.amazonaws.services.s3.internal.DigestValidationInputStream;
import com.amazonaws.services.s3.internal.InputSubstream;
import com.amazonaws.services.s3.internal.MD5DigestCalculatingInputStream;
import com.amazonaws.services.s3.internal.Mimetypes;
import com.amazonaws.services.s3.internal.ObjectExpirationHeaderHandler;
import com.amazonaws.services.s3.internal.RepeatableFileInputStream;
import com.amazonaws.services.s3.internal.RepeatableInputStream;
import com.amazonaws.services.s3.internal.ResponseHeaderHandlerChain;
import com.amazonaws.services.s3.internal.S3ErrorResponseHandler;
import com.amazonaws.services.s3.internal.S3MetadataResponseHandler;
import com.amazonaws.services.s3.internal.S3ObjectResponseHandler;
import com.amazonaws.services.s3.internal.S3QueryStringSigner;
import com.amazonaws.services.s3.internal.S3Signer;
import com.amazonaws.services.s3.internal.S3StringResponseHandler;
import com.amazonaws.services.s3.internal.S3VersionHeaderHandler;
import com.amazonaws.services.s3.internal.S3XmlResponseHandler;
import com.amazonaws.services.s3.internal.ServerSideEncryptionHeaderHandler;
import com.amazonaws.services.s3.internal.ServiceUtils;
import com.amazonaws.services.s3.internal.XmlWriter;
import com.amazonaws.services.s3.model.AbortMultipartUploadRequest;
import com.amazonaws.services.s3.model.AccessControlList;
import com.amazonaws.services.s3.model.AmazonS3Exception;
import com.amazonaws.services.s3.model.Bucket;
import com.amazonaws.services.s3.model.BucketCrossOriginConfiguration;
import com.amazonaws.services.s3.model.BucketLifecycleConfiguration;
import com.amazonaws.services.s3.model.BucketLoggingConfiguration;
import com.amazonaws.services.s3.model.BucketNotificationConfiguration;
import com.amazonaws.services.s3.model.BucketPolicy;
import com.amazonaws.services.s3.model.BucketTaggingConfiguration;
import com.amazonaws.services.s3.model.BucketVersioningConfiguration;
import com.amazonaws.services.s3.model.BucketWebsiteConfiguration;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest;
import com.amazonaws.services.s3.model.CompleteMultipartUploadResult;
import com.amazonaws.services.s3.model.CopyObjectRequest;
import com.amazonaws.services.s3.model.CopyObjectResult;
import com.amazonaws.services.s3.model.CopyPartRequest;
import com.amazonaws.services.s3.model.CopyPartResult;
import com.amazonaws.services.s3.model.CreateBucketRequest;
import com.amazonaws.services.s3.model.DeleteBucketPolicyRequest;
import com.amazonaws.services.s3.model.DeleteBucketRequest;
import com.amazonaws.services.s3.model.DeleteBucketWebsiteConfigurationRequest;
import com.amazonaws.services.s3.model.DeleteObjectRequest;
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
import com.amazonaws.services.s3.model.DeleteObjectsResult;
import com.amazonaws.services.s3.model.DeleteVersionRequest;
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest;
import com.amazonaws.services.s3.model.GenericBucketRequest;
import com.amazonaws.services.s3.model.GetBucketAclRequest;
import com.amazonaws.services.s3.model.GetBucketLocationRequest;
import com.amazonaws.services.s3.model.GetBucketPolicyRequest;
import com.amazonaws.services.s3.model.GetBucketWebsiteConfigurationRequest;
import com.amazonaws.services.s3.model.GetObjectMetadataRequest;
import com.amazonaws.services.s3.model.GetObjectRequest;
import com.amazonaws.services.s3.model.Grant;
import com.amazonaws.services.s3.model.Grantee;
import com.amazonaws.services.s3.model.GroupGrantee;
import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest;
import com.amazonaws.services.s3.model.InitiateMultipartUploadResult;
import com.amazonaws.services.s3.model.ListBucketsRequest;
import com.amazonaws.services.s3.model.ListMultipartUploadsRequest;
import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ListPartsRequest;
import com.amazonaws.services.s3.model.ListVersionsRequest;
import com.amazonaws.services.s3.model.MultiFactorAuthentication;
import com.amazonaws.services.s3.model.MultiObjectDeleteException;
import com.amazonaws.services.s3.model.MultipartUploadListing;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.Owner;
import com.amazonaws.services.s3.model.PartListing;
import com.amazonaws.services.s3.model.Permission;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.amazonaws.services.s3.model.PutObjectResult;
import com.amazonaws.services.s3.model.Region;
import com.amazonaws.services.s3.model.ResponseHeaderOverrides;
import com.amazonaws.services.s3.model.RestoreObjectRequest;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import com.amazonaws.services.s3.model.SetBucketAclRequest;
import com.amazonaws.services.s3.model.SetBucketLoggingConfigurationRequest;
import com.amazonaws.services.s3.model.SetBucketNotificationConfigurationRequest;
import com.amazonaws.services.s3.model.SetBucketPolicyRequest;
import com.amazonaws.services.s3.model.SetBucketVersioningConfigurationRequest;
import com.amazonaws.services.s3.model.SetBucketWebsiteConfigurationRequest;
import com.amazonaws.services.s3.model.StorageClass;
import com.amazonaws.services.s3.model.UploadPartRequest;
import com.amazonaws.services.s3.model.UploadPartResult;
import com.amazonaws.services.s3.model.VersionListing;
import com.amazonaws.services.s3.model.transform.AclXmlFactory;
import com.amazonaws.services.s3.model.transform.BucketConfigurationXmlFactory;
import com.amazonaws.services.s3.model.transform.MultiObjectDeleteXmlFactory;
import com.amazonaws.services.s3.model.transform.RequestXmlFactory;
import com.amazonaws.services.s3.model.transform.Unmarshallers;
import com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.CompleteMultipartUploadHandler;
import com.amazonaws.services.s3.model.transform.XmlResponsesSaxParser.CopyObjectResultHandler;
import com.amazonaws.transform.Unmarshaller;
import com.amazonaws.util.BinaryUtils;
import com.amazonaws.util.ContentLengthValidationInputStream;
import com.amazonaws.util.DateUtils;
import com.amazonaws.util.HttpUtils;
import com.amazonaws.util.Md5Utils;
/**
* <p>
* Provides the client for accessing the Amazon S3 web service.
* </p>
* <p>
* Amazon S3 provides storage for the Internet,
* and is designed to make web-scale computing easier for developers.
* </p>
* <p>
* The Amazon S3 Java SDK provides a simple interface that can be
* used to store and retrieve any amount of data, at any time,
* from anywhere on the web. It gives any developer access to the same
* highly scalable, reliable, secure, fast, inexpensive infrastructure
* that Amazon uses to run its own global network of web sites.
* The service aims to maximize benefits of scale and to pass those
* benefits on to developers.
* </p>
* <p>
* For more information about Amazon S3, please see
* <a href="http://aws.amazon.com/s3">
* http://aws.amazon.com/s3</a>
* </p>
*/
public class AmazonS3Client extends AmazonWebServiceClient implements AmazonS3 {
/** Shared logger for client events */
private static Log log = LogFactory.getLog(AmazonS3Client.class);
/** Responsible for handling error responses from all S3 service calls. */
private S3ErrorResponseHandler errorResponseHandler = new S3ErrorResponseHandler();
/** Shared response handler for operations with no response. */
private S3XmlResponseHandler<Void> voidResponseHandler = new S3XmlResponseHandler<Void>(null);
/** Shared factory for converting configuration objects to XML */
private static final BucketConfigurationXmlFactory bucketConfigurationXmlFactory = new BucketConfigurationXmlFactory();
/** S3 specific client configuration options */
private S3ClientOptions clientOptions = new S3ClientOptions();
/** Provider for AWS credentials. */
private AWSCredentialsProvider awsCredentialsProvider;
/**
* Constructs a new client to invoke service methods on Amazon S3. A
* credentials provider chain will be used that searches for credentials in
* this order:
* <ul>
* <li>Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY</li>
* <li>Java System Properties - aws.accessKeyId and aws.secretKey</li>
* <li>Instance Profile Credentials - delivered through the Amazon EC2
* metadata service</li>
* </ul>
*
* <p>
* If no credentials are found in the chain, this client will attempt to
* work in an anonymous mode where requests aren't signed. Only a subset of
* the Amazon S3 API will work with anonymous <i>(i.e. unsigned)</i> requests,
* but this can prove useful in some situations. For example:
* <ul>
* <li>If an Amazon S3 bucket has {@link Permission#Read} permission for the
* {@link GroupGrantee#AllUsers} group, anonymous clients can call
* {@link #listObjects(String)} to see what objects are stored in a bucket.</li>
* <li>If an object has {@link Permission#Read} permission for the
* {@link GroupGrantee#AllUsers} group, anonymous clients can call
* {@link #getObject(String, String)} and
* {@link #getObjectMetadata(String, String)} to pull object content and
* metadata.</li>
* <li>If a bucket has {@link Permission#Write} permission for the
* {@link GroupGrantee#AllUsers} group, anonymous clients can upload objects
* to the bucket.</li>
* </ul>
* </p>
* <p>
* You can force the client to operate in an anonymous mode, and skip the credentials
* provider chain, by passing in <code>null</code> for the credentials.
* </p>
*
* @see AmazonS3Client#AmazonS3Client(AWSCredentials)
* @see AmazonS3Client#AmazonS3Client(AWSCredentials, ClientConfiguration)
*/
public AmazonS3Client() {
this(new AWSCredentialsProviderChain(
new EnvironmentVariableCredentialsProvider(),
new SystemPropertiesCredentialsProvider(),
new InstanceProfileCredentialsProvider()) {
public AWSCredentials getCredentials() {
try {
return super.getCredentials();
} catch (AmazonClientException ace) {}
log.debug("No credentials available; falling back to anonymous access");
return null;
}
});
}
/**
* Constructs a new Amazon S3 client using the specified AWS credentials to
* access Amazon S3.
*
* @param awsCredentials
* The AWS credentials to use when making requests to Amazon S3
* with this client.
*
* @see AmazonS3Client#AmazonS3Client()
* @see AmazonS3Client#AmazonS3Client(AWSCredentials, ClientConfiguration)
*/
public AmazonS3Client(AWSCredentials awsCredentials) {
this(awsCredentials, new ClientConfiguration());
}
/**
* Constructs a new Amazon S3 client using the specified AWS credentials and
* client configuration to access Amazon S3.
*
* @param awsCredentials
* The AWS credentials to use when making requests to Amazon S3
* with this client.
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to Amazon S3 (e.g. proxy settings, retry counts, etc).
*
* @see AmazonS3Client#AmazonS3Client()
* @see AmazonS3Client#AmazonS3Client(AWSCredentials)
*/
public AmazonS3Client(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) {
super(clientConfiguration);
this.awsCredentialsProvider = new StaticCredentialsProvider(awsCredentials);
init();
}
/**
* Constructs a new Amazon S3 client using the specified AWS credentials
* provider to access Amazon S3.
*
* @param credentialsProvider
* The AWS credentials provider which will provide credentials
* to authenticate requests with AWS services.
*/
public AmazonS3Client(AWSCredentialsProvider credentialsProvider) {
this(credentialsProvider, new ClientConfiguration());
}
/**
* Constructs a new Amazon S3 client using the specified AWS credentials and
* client configuration to access Amazon S3.
*
* @param credentialsProvider
* The AWS credentials provider which will provide credentials
* to authenticate requests with AWS services.
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to Amazon S3 (e.g. proxy settings, retry counts, etc).
*/
public AmazonS3Client(AWSCredentialsProvider credentialsProvider, ClientConfiguration clientConfiguration) {
super(clientConfiguration);
this.awsCredentialsProvider = credentialsProvider;
init();
}
/**
* Constructs a new client using the specified client configuration to
* access Amazon S3. A credentials provider chain will be used that searches
* for credentials in this order:
* <ul>
* <li>Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY</li>
* <li>Java System Properties - aws.accessKeyId and aws.secretKey</li>
* <li>Instance Profile Credentials - delivered through the Amazon EC2
* metadata service</li>
* </ul>
*
* <p>
* If no credentials are found in the chain, this client will attempt to
* work in an anonymous mode where requests aren't signed. Only a subset of
* the Amazon S3 API will work with anonymous <i>(i.e. unsigned)</i>
* requests, but this can prove useful in some situations. For example:
* <ul>
* <li>If an Amazon S3 bucket has {@link Permission#Read} permission for the
* {@link GroupGrantee#AllUsers} group, anonymous clients can call
* {@link #listObjects(String)} to see what objects are stored in a bucket.</li>
* <li>If an object has {@link Permission#Read} permission for the
* {@link GroupGrantee#AllUsers} group, anonymous clients can call
* {@link #getObject(String, String)} and
* {@link #getObjectMetadata(String, String)} to pull object content and
* metadata.</li>
* <li>If a bucket has {@link Permission#Write} permission for the
* {@link GroupGrantee#AllUsers} group, anonymous clients can upload objects
* to the bucket.</li>
* </ul>
* </p>
* <p>
* You can force the client to operate in an anonymous mode, and skip the
* credentials provider chain, by passing in <code>null</code> for the
* credentials.
* </p>
*
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to Amazon S3 (e.g. proxy settings, retry counts, etc).
*
* @see AmazonS3Client#AmazonS3Client(AWSCredentials)
* @see AmazonS3Client#AmazonS3Client(AWSCredentials, ClientConfiguration)
*/
public AmazonS3Client(ClientConfiguration clientConfiguration) {
this(new DefaultAWSCredentialsProviderChain(), clientConfiguration);
}
private void init() {
// Because of S3's virtual host style addressing, we need to change the
// default, strict hostname verification to be more lenient.
client.disableStrictHostnameVerification();
setEndpoint(Constants.S3_HOSTNAME);
HandlerChainFactory chainFactory = new HandlerChainFactory();
requestHandlers.addAll(chainFactory.newRequestHandlerChain(
"/com/amazonaws/services/s3/request.handlers"));
}
/* (non-Javadoc)
* @see com.amazonaws.AmazonWebServiceClient#getServiceAbbreviation()
*/
@Override
protected String getServiceAbbreviation() {
return "s3";
}
/**
* <p>
* Override the default S3 client options for this client.
* </p>
* @param clientOptions
* The S3 client options to use.
*/
public void setS3ClientOptions(S3ClientOptions clientOptions) {
this.clientOptions = new S3ClientOptions(clientOptions);
}
/**
* Appends a request handler to the list of registered handlers that are run
* as part of a request's lifecycle.
*
* @param requestHandler
* The new handler to add to the current list of request
* handlers.
*/
public void addRequestHandler(RequestHandler requestHandler) {
requestHandlers.add(requestHandler);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listNextBatchOfVersions(com.amazonaws.services.s3.model.S3VersionListing)
*/
public VersionListing listNextBatchOfVersions(VersionListing previousVersionListing)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(previousVersionListing,
"The previous version listing parameter must be specified when listing the next batch of versions in a bucket");
if (!previousVersionListing.isTruncated()) {
VersionListing emptyListing = new VersionListing();
emptyListing.setBucketName(previousVersionListing.getBucketName());
emptyListing.setDelimiter(previousVersionListing.getDelimiter());
emptyListing.setKeyMarker(previousVersionListing.getNextKeyMarker());
emptyListing.setVersionIdMarker(previousVersionListing.getNextVersionIdMarker());
emptyListing.setMaxKeys(previousVersionListing.getMaxKeys());
emptyListing.setPrefix(previousVersionListing.getPrefix());
emptyListing.setTruncated(false);
return emptyListing;
}
return listVersions(new ListVersionsRequest(
previousVersionListing.getBucketName(),
previousVersionListing.getPrefix(),
previousVersionListing.getNextKeyMarker(),
previousVersionListing.getNextVersionIdMarker(),
previousVersionListing.getDelimiter(),
new Integer( previousVersionListing.getMaxKeys() ) ));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listVersions(java.lang.String, java.lang.String)
*/
public VersionListing listVersions(String bucketName, String prefix)
throws AmazonClientException, AmazonServiceException {
return listVersions(new ListVersionsRequest(bucketName, prefix, null, null, null, null));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listVersions(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Integer)
*/
public VersionListing listVersions(String bucketName, String prefix, String keyMarker, String versionIdMarker, String delimiter, Integer maxKeys)
throws AmazonClientException, AmazonServiceException {
ListVersionsRequest request = new ListVersionsRequest()
.withBucketName(bucketName)
.withPrefix(prefix)
.withDelimiter(delimiter)
.withKeyMarker(keyMarker)
.withVersionIdMarker(versionIdMarker)
.withMaxResults(maxKeys);
return listVersions(request);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listVersions(com.amazonaws.services.s3.model.ListVersionsRequest)
*/
public VersionListing listVersions(ListVersionsRequest listVersionsRequest)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(listVersionsRequest.getBucketName(), "The bucket name parameter must be specified when listing versions in a bucket");
Request<ListVersionsRequest> request = createRequest(listVersionsRequest.getBucketName(), null, listVersionsRequest, HttpMethodName.GET);
request.addParameter("versions", null);
if (listVersionsRequest.getPrefix() != null) request.addParameter("prefix", listVersionsRequest.getPrefix());
if (listVersionsRequest.getKeyMarker() != null) request.addParameter("key-marker", listVersionsRequest.getKeyMarker());
if (listVersionsRequest.getVersionIdMarker() != null) request.addParameter("version-id-marker", listVersionsRequest.getVersionIdMarker());
if (listVersionsRequest.getDelimiter() != null) request.addParameter("delimiter", listVersionsRequest.getDelimiter());
if (listVersionsRequest.getMaxResults() != null && listVersionsRequest.getMaxResults().intValue() >= 0) request.addParameter("max-keys", listVersionsRequest.getMaxResults().toString());
return invoke(request, new Unmarshallers.VersionListUnmarshaller(), listVersionsRequest.getBucketName(), null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listObjects(java.lang.String)
*/
public ObjectListing listObjects(String bucketName)
throws AmazonClientException, AmazonServiceException {
return listObjects(new ListObjectsRequest(bucketName, null, null, null, null));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listObjects(java.lang.String, java.lang.String)
*/
public ObjectListing listObjects(String bucketName, String prefix)
throws AmazonClientException, AmazonServiceException {
return listObjects(new ListObjectsRequest(bucketName, prefix, null, null, null));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listObjects(com.amazonaws.services.s3.model.ListObjectsRequest)
*/
public ObjectListing listObjects(ListObjectsRequest listObjectsRequest)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(listObjectsRequest.getBucketName(), "The bucket name parameter must be specified when listing objects in a bucket");
Request<ListObjectsRequest> request = createRequest(listObjectsRequest.getBucketName(), null, listObjectsRequest, HttpMethodName.GET);
if (listObjectsRequest.getPrefix() != null) request.addParameter("prefix", listObjectsRequest.getPrefix());
if (listObjectsRequest.getMarker() != null) request.addParameter("marker", listObjectsRequest.getMarker());
if (listObjectsRequest.getDelimiter() != null) request.addParameter("delimiter", listObjectsRequest.getDelimiter());
if (listObjectsRequest.getMaxKeys() != null && listObjectsRequest.getMaxKeys().intValue() >= 0) request.addParameter("max-keys", listObjectsRequest.getMaxKeys().toString());
return invoke(request, new Unmarshallers.ListObjectsUnmarshaller(), listObjectsRequest.getBucketName(), null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listNextBatchOfObjects(com.amazonaws.services.s3.model.S3ObjectListing)
*/
public ObjectListing listNextBatchOfObjects(ObjectListing previousObjectListing)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(previousObjectListing,
"The previous object listing parameter must be specified when listing the next batch of objects in a bucket");
if (!previousObjectListing.isTruncated()) {
ObjectListing emptyListing = new ObjectListing();
emptyListing.setBucketName(previousObjectListing.getBucketName());
emptyListing.setDelimiter(previousObjectListing.getDelimiter());
emptyListing.setMarker(previousObjectListing.getNextMarker());
emptyListing.setMaxKeys(previousObjectListing.getMaxKeys());
emptyListing.setPrefix(previousObjectListing.getPrefix());
emptyListing.setTruncated(false);
return emptyListing;
}
return listObjects(new ListObjectsRequest(
previousObjectListing.getBucketName(),
previousObjectListing.getPrefix(),
previousObjectListing.getNextMarker(),
previousObjectListing.getDelimiter(),
new Integer( previousObjectListing.getMaxKeys() ) ));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getS3AccountOwner()
*/
public Owner getS3AccountOwner()
throws AmazonClientException, AmazonServiceException {
Request<ListBucketsRequest> request = createRequest(null, null, new ListBucketsRequest(), HttpMethodName.GET);
return invoke(request, new Unmarshallers.ListBucketsOwnerUnmarshaller(), null, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listBuckets()
*/
public List<Bucket> listBuckets(ListBucketsRequest listBucketsRequest)
throws AmazonClientException, AmazonServiceException {
Request<ListBucketsRequest> request = createRequest(null, null, listBucketsRequest, HttpMethodName.GET);
return invoke(request, new Unmarshallers.ListBucketsUnmarshaller(), null, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#listBuckets()
*/
public List<Bucket> listBuckets()
throws AmazonClientException, AmazonServiceException {
return listBuckets(new ListBucketsRequest());
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getBucketLocation(com.amazonaws.services.s3.AmazonS3Client.GetBucketLocationRequest)
*/
public String getBucketLocation(GetBucketLocationRequest getBucketLocationRequest)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(getBucketLocationRequest, "The request parameter must be specified when requesting a bucket's location");
String bucketName = getBucketLocationRequest.getBucketName();
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when requesting a bucket's location");
Request<GetBucketLocationRequest> request = createRequest(bucketName, null, getBucketLocationRequest, HttpMethodName.GET);
request.addParameter("location", null);
return invoke(request, new Unmarshallers.BucketLocationUnmarshaller(), bucketName, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getBucketLocation(java.lang.String)
*/
public String getBucketLocation(String bucketName)
throws AmazonClientException, AmazonServiceException {
return getBucketLocation(new GetBucketLocationRequest(bucketName));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#createBucket(java.lang.String)
*/
public Bucket createBucket(String bucketName)
throws AmazonClientException, AmazonServiceException {
return createBucket(new CreateBucketRequest(bucketName));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#createBucket(java.lang.String, com.amazonaws.services.s3.model.Region)
*/
public Bucket createBucket(String bucketName, Region region)
throws AmazonClientException, AmazonServiceException {
return createBucket(new CreateBucketRequest(bucketName, region));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#createBucket(java.lang.String, java.lang.String)
*/
public Bucket createBucket(String bucketName, String region)
throws AmazonClientException, AmazonServiceException {
return createBucket(new CreateBucketRequest(bucketName, region));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#createBucket(com.amazonaws.services.s3.model.CreateBucketRequest)
*/
public Bucket createBucket(CreateBucketRequest createBucketRequest)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(createBucketRequest,
"The CreateBucketRequest parameter must be specified when creating a bucket");
String bucketName = createBucketRequest.getBucketName();
String region = createBucketRequest.getRegion();
assertParameterNotNull(bucketName,
"The bucket name parameter must be specified when creating a bucket");
if (bucketName != null) bucketName = bucketName.trim();
BucketNameUtils.validateBucketName(bucketName);
Request<CreateBucketRequest> request = createRequest(bucketName, null, createBucketRequest, HttpMethodName.PUT);
if ( createBucketRequest.getAccessControlList() != null ) {
addAclHeaders(request, createBucketRequest.getAccessControlList());
} else if ( createBucketRequest.getCannedAcl() != null ) {
request.addHeader(Headers.S3_CANNED_ACL, createBucketRequest.getCannedAcl().toString());
}
/*
* If we're talking to a region-specific endpoint other than the US, we
* *must* specify a location constraint. Try to derive the region from
* the endpoint.
*/
if (!(this.endpoint.getHost().equals(Constants.S3_HOSTNAME))
&& (region == null || region.isEmpty())) {
region = RegionUtils.getRegionByEndpoint(this.endpoint.getHost())
.getName();
}
/*
* We can only send the CreateBucketConfiguration if we're *not*
* creating a bucket in the US region.
*/
if (region != null && !region.toUpperCase().equals(Region.US_Standard.toString())) {
XmlWriter xml = new XmlWriter();
xml.start("CreateBucketConfiguration", "xmlns", Constants.XML_NAMESPACE);
xml.start("LocationConstraint").value(region).end();
xml.end();
request.setContent(new ByteArrayInputStream(xml.getBytes()));
}
invoke(request, voidResponseHandler, bucketName, null);
return new Bucket(bucketName);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getObjectAcl(java.lang.String, java.lang.String)
*/
public AccessControlList getObjectAcl(String bucketName, String key)
throws AmazonClientException, AmazonServiceException {
return getObjectAcl(bucketName, key, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getObjectAcl(java.lang.String, java.lang.String, java.lang.String)
*/
public AccessControlList getObjectAcl(String bucketName, String key, String versionId)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when requesting an object's ACL");
assertParameterNotNull(key, "The key parameter must be specified when requesting an object's ACL");
return getAcl(bucketName, key, versionId, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setObjectAcl(java.lang.String, java.lang.String, com.amazonaws.services.s3.model.AccessControlList)
*/
public void setObjectAcl(String bucketName, String key, AccessControlList acl)
throws AmazonClientException, AmazonServiceException {
setObjectAcl(bucketName, key, null, acl);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setObjectAcl(java.lang.String, java.lang.String, com.amazonaws.services.s3.model.CannedAccessControlList)
*/
public void setObjectAcl(String bucketName, String key, CannedAccessControlList acl)
throws AmazonClientException, AmazonServiceException {
setObjectAcl(bucketName, key, null, acl);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setObjectAcl(java.lang.String, java.lang.String, java.lang.String, com.amazonaws.services.s3.model.AccessControlList)
*/
public void setObjectAcl(String bucketName, String key, String versionId, AccessControlList acl)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when setting an object's ACL");
assertParameterNotNull(key, "The key parameter must be specified when setting an object's ACL");
assertParameterNotNull(acl, "The ACL parameter must be specified when setting an object's ACL");
setAcl(bucketName, key, versionId, acl, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setObjectAcl(java.lang.String, java.lang.String, java.lang.String, com.amazonaws.services.s3.model.CannedAccessControlList)
*/
public void setObjectAcl(String bucketName, String key, String versionId, CannedAccessControlList acl)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when setting an object's ACL");
assertParameterNotNull(key, "The key parameter must be specified when setting an object's ACL");
assertParameterNotNull(acl, "The ACL parameter must be specified when setting an object's ACL");
setAcl(bucketName, key, versionId, acl, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getBucketAcl(java.lang.String)
*/
public AccessControlList getBucketAcl(String bucketName)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when requesting a bucket's ACL");
return getAcl(bucketName, null, null, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getBucketAcl(com.amazonaws.services.s3.GetBucketAclRequest)
*/
public AccessControlList getBucketAcl(GetBucketAclRequest getBucketAclRequest)
throws AmazonClientException, AmazonServiceException {
String bucketName = getBucketAclRequest.getBucketName();
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when requesting a bucket's ACL");
return getAcl(bucketName, null, null, getBucketAclRequest);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setBucketAcl(java.lang.String, com.amazonaws.services.s3.model.AccessControlList)
*/
public void setBucketAcl(String bucketName, AccessControlList acl)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when setting a bucket's ACL");
assertParameterNotNull(acl, "The ACL parameter must be specified when setting a bucket's ACL");
setAcl(bucketName, null, null, acl, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setBucketAcl(com.amazonaws.services.s3.SetBucketAclRequest)
*/
public void setBucketAcl(SetBucketAclRequest setBucketAclRequest)
throws AmazonClientException, AmazonServiceException {
String bucketName = setBucketAclRequest.getBucketName();
AccessControlList acl = setBucketAclRequest.getAcl();
CannedAccessControlList cannedAcl = setBucketAclRequest.getCannedAcl();
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when setting a bucket's ACL");
if (acl != null) {
setAcl(bucketName, null, null, acl, setBucketAclRequest);
} else if (cannedAcl != null) {
setAcl(bucketName, null, null, cannedAcl, setBucketAclRequest);
} else {
assertParameterNotNull(null, "The ACL parameter must be specified when setting a bucket's ACL");
}
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setBucketAcl(java.lang.String, com.amazonaws.services.s3.model.CannedAccessControlList)
*/
public void setBucketAcl(String bucketName, CannedAccessControlList acl)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when setting a bucket's ACL");
assertParameterNotNull(acl, "The ACL parameter must be specified when setting a bucket's ACL");
setAcl(bucketName, null, null, acl, null);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getObjectMetadata(java.lang.String, java.lang.String)
*/
public ObjectMetadata getObjectMetadata(String bucketName, String key)
throws AmazonClientException, AmazonServiceException {
return getObjectMetadata(new GetObjectMetadataRequest(bucketName, key));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getObjectMetadata(com.amazonaws.services.s3.model.GetObjectMetadataRequest)
*/
public ObjectMetadata getObjectMetadata(GetObjectMetadataRequest getObjectMetadataRequest)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(getObjectMetadataRequest, "The GetObjectMetadataRequest parameter must be specified when requesting an object's metadata");
String bucketName = getObjectMetadataRequest.getBucketName();
String key = getObjectMetadataRequest.getKey();
String versionId = getObjectMetadataRequest.getVersionId();
assertParameterNotNull(bucketName, "The bucket name parameter must be specified when requesting an object's metadata");
assertParameterNotNull(key, "The key parameter must be specified when requesting an object's metadata");
Request<GetObjectMetadataRequest> request = createRequest(bucketName, key, getObjectMetadataRequest, HttpMethodName.HEAD);
if (versionId != null) request.addParameter("versionId", versionId);
return invoke(request, new S3MetadataResponseHandler(), bucketName, key);
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getObject(java.lang.String, java.lang.String)
*/
public S3Object getObject(String bucketName, String key)
throws AmazonClientException, AmazonServiceException {
return getObject(new GetObjectRequest(bucketName, key));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#doesBucketExist(java.lang.String)
*/
public boolean doesBucketExist(String bucketName)
throws AmazonClientException, AmazonServiceException {
try {
listObjects(new ListObjectsRequest(bucketName, null, null, null, 0));
// it exists and the current account owns it
return true;
} catch (AmazonServiceException ase) {
/*
* If we have no credentials, or we detect a problem with the
* credentials we used, go ahead and throw the error so we don't
* mask that problem as thinking that the bucket does exist.
*/
if (awsCredentialsProvider.getCredentials() == null) throw ase;
if (ase.getErrorCode().equalsIgnoreCase("InvalidAccessKeyId") ||
ase.getErrorCode().equalsIgnoreCase("SignatureDoesNotMatch")) {
throw ase;
}
switch (ase.getStatusCode()) {
case 301:
// A redirect error means the bucket exists, but in another region.
return true;
case 403:
// A permissions error means the bucket exists, but is owned by another account.
return true;
case 404:
return false;
default:
throw ase;
}
}
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#changeStorageClass(java.lang.String, java.lang.String, java.lang.String)
*/
public void changeObjectStorageClass(String bucketName, String key, StorageClass newStorageClass)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName,
"The bucketName parameter must be specified when changing an object's storage class");
assertParameterNotNull(key,
"The key parameter must be specified when changing an object's storage class");
assertParameterNotNull(newStorageClass,
"The newStorageClass parameter must be specified when changing an object's storage class");
copyObject(new CopyObjectRequest(bucketName, key, bucketName, key)
.withStorageClass(newStorageClass.toString()));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#setObjectRedirectLocation(java.lang.String, java.lang.String, java.lang.String)
*/
public void setObjectRedirectLocation(String bucketName, String key, String newRedirectLocation)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(bucketName,
"The bucketName parameter must be specified when changing an object's storage class");
assertParameterNotNull(key,
"The key parameter must be specified when changing an object's storage class");
assertParameterNotNull(newRedirectLocation,
"The newStorageClass parameter must be specified when changing an object's storage class");
copyObject(new CopyObjectRequest(bucketName, key, bucketName, key)
.withRedirectLocation(newRedirectLocation));
}
/* (non-Javadoc)
* @see com.amazonaws.services.s3.AmazonS3#getObject(com.amazonaws.services.s3.model.GetObjectRequest)
*/
public S3Object getObject(GetObjectRequest getObjectRequest)
throws AmazonClientException, AmazonServiceException {
assertParameterNotNull(getObjectRequest,
"The GetObjectRequest parameter must be specified when requesting an object");
assertParameterNotNull(getObjectRequest.getBucketName(),
"The bucket name parameter must be specified when requesting an object");
assertParameterNotNull(getObjectRequest.getKey(),
"The key parameter must be specified when requesting an object");
Request<GetObjectRequest> request = createRequest(getObjectRequest.getBucketName(), getObjectRequest.getKey(), getObjectRequest, HttpMethodName.GET);
if (getObjectRequest.getVersionId() != null) {
request.addParameter("versionId", getObjectRequest.getVersionId());
}
// Range
if (getObjectRequest.getRange() != null) {
long[] range = getObjectRequest.getRange();
request.addHeader(Headers.RANGE, "bytes=" + Long.toString(range[0]) + "-" + Long.toString(range[1]));
}
addResponseHeaderParameters(request, getObjectRequest.getResponseHeaders());
addDateHeader(request, Headers.GET_OBJECT_IF_MODIFIED_SINCE,
getObjectRequest.getModifiedSinceConstraint());
addDateHeader(request, Headers.GET_OBJECT_IF_UNMODIFIED_SINCE,
getObjectRequest.getUnmodifiedSinceConstraint());
addStringListHeader(request, Headers.GET_OBJECT_IF_MATCH,
getObjectRequest.getMatchingETagConstraints());
addStringListHeader(request, Headers.GET_OBJECT_IF_NONE_MATCH,
getObjectRequest.getNonmatchingETagConstraints());
/*
* This is compatible with progress listener set by either the legacy
* method GetObjectRequest#setProgressListener or the new method
* GetObjectRequest#setGeneralProgressListener.
*/
ProgressListener progressListener = getObjectRequest.getGeneralProgressListener();
ProgressListenerCallbackExecutor progressListenerCallbackExecutor = ProgressListenerCallbackExecutor
.wrapListener(progressListener);
try {
S3Object s3Object = invoke(request, new S3ObjectResponseHandler(), getObjectRequest.getBucketName(), getObjectRequest.getKey());
/*
* TODO: For now, it's easiest to set there here in the client, but
* we could push this back into the response handler with a
* little more work.
*/
s3Object.setBucketName(getObjectRequest.getBucketName());
s3Object.setKey(getObjectRequest.getKey());
S3ObjectInputStream input = s3Object.getObjectContent();
if (progressListenerCallbackExecutor != null) {
ProgressReportingInputStream progressReportingInputStream = new ProgressReportingInputStream(input, progressListenerCallbackExecutor);
progressReportingInputStream.setFireCompletedEvent(true);
input = new S3ObjectInputStream(progressReportingInputStream, input.getHttpRequest());
fireProgressEvent(progressListenerCallbackExecutor, ProgressEvent.STARTED_EVENT_CODE);
}
if (getObjectRequest.getRange() == null && System.getProperty("com.amazonaws.services.s3.disableGetObjectMD5Validation") == null) {
byte[] serverSideHash = null;
String etag = s3Object.getObjectMetadata().getETag();
if (etag != null && ServiceUtils.isMultipartUploadETag(etag) == false) {
serverSideHash = BinaryUtils.fromHex(s3Object.getObjectMetadata().getETag());
DigestValidationInputStream inputStreamWithMD5DigestValidation;
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
inputStreamWithMD5DigestValidation = new DigestValidationInputStream(input, digest, serverSideHash);
input = new S3ObjectInputStream(inputStreamWithMD5DigestValidation, input.getHttpRequest());
} catch (NoSuchAlgorithmException e) {
log.warn("No MD5 digest algorithm available. Unable to calculate "
+ "checksum and verify data integrity.", e);
}
}
} else {
input = new S3ObjectInputStream(
new ContentLengthValidationInputStream(input, s3Object.getObjectMetadata().getContentLength()),
input.getHttpRequest());
}