2020 *
2121 */
2222
23+ using System ;
2324using System . Collections . Generic ;
2425using Amazon . S3 . Model ;
2526
@@ -37,10 +38,11 @@ internal static class ResponseMapper
3738 /// </summary>
3839 /// <param name="source">The PutObjectResponse to map from</param>
3940 /// <returns>A new TransferUtilityUploadResponse with mapped fields</returns>
41+ /// <exception cref="ArgumentNullException">Thrown when source is null</exception>
4042 internal static TransferUtilityUploadResponse MapPutObjectResponse ( PutObjectResponse source )
4143 {
4244 if ( source == null )
43- return null ;
45+ throw new ArgumentNullException ( nameof ( source ) ) ;
4446
4547 var response = new TransferUtilityUploadResponse ( ) ;
4648
@@ -76,10 +78,11 @@ internal static TransferUtilityUploadResponse MapPutObjectResponse(PutObjectResp
7678 /// </summary>
7779 /// <param name="source">The CompleteMultipartUploadResponse to map from</param>
7880 /// <returns>A new TransferUtilityUploadResponse with mapped fields</returns>
81+ /// <exception cref="ArgumentNullException">Thrown when source is null</exception>
7982 internal static TransferUtilityUploadResponse MapCompleteMultipartUploadResponse ( CompleteMultipartUploadResponse source )
8083 {
8184 if ( source == null )
82- return null ;
85+ throw new ArgumentNullException ( nameof ( source ) ) ;
8386
8487 var response = new TransferUtilityUploadResponse ( ) ;
8588
@@ -106,61 +109,97 @@ internal static TransferUtilityUploadResponse MapCompleteMultipartUploadResponse
106109 return response ;
107110 }
108111
112+ /// <summary>
113+ /// Private helper method to populate the common properties from GetObjectResponse to the base response class.
114+ /// Contains all the shared mapping logic for GetObjectResponse fields.
115+ /// </summary>
116+ /// <param name="source">The GetObjectResponse to map from</param>
117+ /// <param name="target">The TransferUtilityGetObjectResponseBase to populate</param>
118+ /// <exception cref="ArgumentNullException">Thrown when source or target is null</exception>
119+ private static void PopulateGetObjectResponseBase ( GetObjectResponse source , TransferUtilityGetObjectResponseBase target )
120+ {
121+ if ( source == null )
122+ throw new ArgumentNullException ( nameof ( source ) ) ;
123+ if ( target == null )
124+ throw new ArgumentNullException ( nameof ( target ) ) ;
125+
126+ // Map all fields as defined in mapping.json "Conversion" -> "GetObjectResponse" -> "DownloadResponse"
127+ target . AcceptRanges = source . AcceptRanges ;
128+ target . BucketKeyEnabled = source . BucketKeyEnabled . GetValueOrDefault ( ) ;
129+ target . ChecksumCRC32 = source . ChecksumCRC32 ;
130+ target . ChecksumCRC32C = source . ChecksumCRC32C ;
131+ target . ChecksumCRC64NVME = source . ChecksumCRC64NVME ;
132+ target . ChecksumSHA1 = source . ChecksumSHA1 ;
133+ target . ChecksumSHA256 = source . ChecksumSHA256 ;
134+ target . ChecksumType = source . ChecksumType ;
135+ target . ContentRange = source . ContentRange ;
136+ target . Headers = source . Headers ;
137+ target . DeleteMarker = source . DeleteMarker ;
138+ target . ETag = source . ETag ;
139+ target . Expiration = source . Expiration ;
140+ target . ExpiresString = source . ExpiresString ;
141+ target . LastModified = source . LastModified ;
142+ target . Metadata = source . Metadata ;
143+ target . MissingMeta = source . MissingMeta ;
144+ target . ObjectLockLegalHoldStatus = source . ObjectLockLegalHoldStatus ;
145+ target . ObjectLockMode = source . ObjectLockMode ;
146+ target . ObjectLockRetainUntilDate = source . ObjectLockRetainUntilDate ;
147+ target . PartsCount = source . PartsCount ;
148+ target . ReplicationStatus = source . ReplicationStatus ;
149+ target . RequestCharged = source . RequestCharged ;
150+ target . RestoreExpiration = source . RestoreExpiration ;
151+ target . RestoreInProgress = source . RestoreInProgress ;
152+ target . ServerSideEncryptionCustomerMethod = source . ServerSideEncryptionCustomerMethod ;
153+ target . ServerSideEncryptionCustomerProvidedKeyMD5 = source . ServerSideEncryptionCustomerProvidedKeyMD5 ;
154+ target . ServerSideEncryptionKeyManagementServiceKeyId = source . ServerSideEncryptionKeyManagementServiceKeyId ;
155+ target . ServerSideEncryptionMethod = source . ServerSideEncryptionMethod ;
156+ target . StorageClass = source . StorageClass ;
157+ target . TagCount = source . TagCount ;
158+ target . VersionId = source . VersionId ;
159+ target . WebsiteRedirectLocation = source . WebsiteRedirectLocation ;
160+
161+ // Copy response metadata
162+ target . ResponseMetadata = source . ResponseMetadata ;
163+ target . ContentLength = source . ContentLength ;
164+ target . HttpStatusCode = source . HttpStatusCode ;
165+ }
166+
109167 /// <summary>
110168 /// Maps a GetObjectResponse to TransferUtilityDownloadResponse.
111169 /// Uses the field mappings defined in mapping.json "Conversion" -> "GetObjectResponse" -> "DownloadResponse".
112170 /// </summary>
113171 /// <param name="source">The GetObjectResponse to map from</param>
114172 /// <returns>A new TransferUtilityDownloadResponse with mapped fields</returns>
173+ /// <exception cref="ArgumentNullException">Thrown when source is null</exception>
115174 internal static TransferUtilityDownloadResponse MapGetObjectResponse ( GetObjectResponse source )
116175 {
117176 if ( source == null )
118- return null ;
177+ throw new ArgumentNullException ( nameof ( source ) ) ;
119178
120179 var response = new TransferUtilityDownloadResponse ( ) ;
180+ PopulateGetObjectResponseBase ( source , response ) ;
181+ return response ;
182+ }
121183
122- // Map all fields as defined in mapping.json "Conversion" -> "GetObjectResponse" -> "DownloadResponse"
123- response . AcceptRanges = source . AcceptRanges ;
124- response . BucketKeyEnabled = source . BucketKeyEnabled . GetValueOrDefault ( ) ;
125- response . ChecksumCRC32 = source . ChecksumCRC32 ;
126- response . ChecksumCRC32C = source . ChecksumCRC32C ;
127- response . ChecksumCRC64NVME = source . ChecksumCRC64NVME ;
128- response . ChecksumSHA1 = source . ChecksumSHA1 ;
129- response . ChecksumSHA256 = source . ChecksumSHA256 ;
130- response . ChecksumType = source . ChecksumType ;
131- response . ContentRange = source . ContentRange ;
132- response . Headers = source . Headers ;
133- response . DeleteMarker = source . DeleteMarker ;
134- response . ETag = source . ETag ;
135- response . Expiration = source . Expiration ;
136- response . ExpiresString = source . ExpiresString ;
137- response . LastModified = source . LastModified ;
138- response . Metadata = source . Metadata ;
139- response . MissingMeta = source . MissingMeta ;
140- response . ObjectLockLegalHoldStatus = source . ObjectLockLegalHoldStatus ;
141- response . ObjectLockMode = source . ObjectLockMode ;
142- response . ObjectLockRetainUntilDate = source . ObjectLockRetainUntilDate ;
143- response . PartsCount = source . PartsCount ;
144- response . ReplicationStatus = source . ReplicationStatus ;
145- response . RequestCharged = source . RequestCharged ;
146- response . RestoreExpiration = source . RestoreExpiration ;
147- response . RestoreInProgress = source . RestoreInProgress ;
148- response . ServerSideEncryptionCustomerMethod = source . ServerSideEncryptionCustomerMethod ;
149- response . ServerSideEncryptionCustomerProvidedKeyMD5 = source . ServerSideEncryptionCustomerProvidedKeyMD5 ;
150- response . ServerSideEncryptionKeyManagementServiceKeyId = source . ServerSideEncryptionKeyManagementServiceKeyId ;
151- response . ServerSideEncryptionMethod = source . ServerSideEncryptionMethod ;
152- response . StorageClass = source . StorageClass ;
153- response . TagCount = source . TagCount ;
154- response . VersionId = source . VersionId ;
155- response . WebsiteRedirectLocation = source . WebsiteRedirectLocation ;
184+ /// <summary>
185+ /// Maps a GetObjectResponse to TransferUtilityOpenStreamResponse.
186+ /// Uses the same field mappings as DownloadResponse plus the ResponseStream property.
187+ /// </summary>
188+ /// <param name="source">The GetObjectResponse to map from</param>
189+ /// <returns>A new TransferUtilityOpenStreamResponse with mapped fields</returns>
190+ /// <exception cref="ArgumentNullException">Thrown when source is null</exception>
191+ internal static TransferUtilityOpenStreamResponse MapGetObjectResponseToOpenStream ( GetObjectResponse source )
192+ {
193+ if ( source == null )
194+ throw new ArgumentNullException ( nameof ( source ) ) ;
156195
157- // Copy response metadata
158- response . ResponseMetadata = source . ResponseMetadata ;
159- response . ContentLength = source . ContentLength ;
160- response . HttpStatusCode = source . HttpStatusCode ;
196+ var response = new TransferUtilityOpenStreamResponse ( ) ;
197+ PopulateGetObjectResponseBase ( source , response ) ;
198+ response . ResponseStream = source . ResponseStream ;
161199
162- return response ;
200+ return response ;
163201 }
202+
164203
165204 }
166205}
0 commit comments