}
};
List<S3Object> partObjects = null;
try {
ThreadedS3Service threadedS3Service =
new ThreadedS3Service(s3Service, eventListener);
threadedS3Service.addServiceEventListener(
captureMultipartUploadObjectsEventAdaptor);
// Build map from object key to storage object
final Map<String, StorageObject> objectsByKey =
new HashMap<String, StorageObject>();
for (StorageObject object: objectsForMultipartUpload) {
objectsByKey.put(object.getKey(), object);
}
// Start all multipart uploads
threadedS3Service.multipartStartUploads(bucketName, objectsForMultipartUpload);
throwServiceEventAdaptorErrorIfPresent(eventListener);
// Build upload and part lists from new multipart uploads, where new
// MultipartUpload objects were captured by this method's
// captureMultipartUploadObjectsEventAdaptor)
for (MultipartUpload upload: multipartUploadList) {
StorageObject object = objectsByKey.get(upload.getObjectKey());
if (object.getDataInputFile() == null) {
throw new ServiceException();
}
partObjects = splitFileIntoObjectsByMaxPartSize(
upload.getObjectKey(),
object.getDataInputFile());
uploadAndPartsList.add(
new MultipartUploadAndParts(upload, partObjects));
}
// Upload all parts for all multipart uploads
threadedS3Service.multipartUploadParts(uploadAndPartsList);
throwServiceEventAdaptorErrorIfPresent(eventListener);
// Complete all multipart uploads
threadedS3Service.multipartCompleteUploads(multipartUploadList);
throwServiceEventAdaptorErrorIfPresent(eventListener);
} catch (Exception e) {
if (partObjects != null && partObjects.size() > 0) {
for (S3Object partObject: partObjects) {
partObject.closeDataInputStream();