

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 1.x 和 2.x 之間的串流操作差異 適用於 Java 的 AWS SDK
<a name="migration-streaming-ops"></a>

串流操作，例如 Amazon S3 `getObject`和 `putObject` 方法，支援 SDK 2.x 版中的非封鎖 I/O。因此，請求和回應模型物件不再以 `InputStream`做為參數。相反地，對於同步請求，請求物件接受 `RequestBody`，這是位元組串流。非同步對等項目接受 `AsyncRequestBody`。

**Example 1.x 中 Amazon S3 `putObject`操作的**  

```
s3client.putObject(BUCKET, KEY, new File(file_path));
```

**Example 2.x 中的 Amazon S3 `putObject`操作**  

```
s3client.putObject(PutObjectRequest.builder()
                                 .bucket(BUCKET)
                                 .key(KEY)
                                 .build(),
                 RequestBody.of(Paths.get("myfile.in")));
```

串流回應物件接受同步用戶端`ResponseTransformer`的 ，以及 V2 中非同步用戶端`AsyncResponseTransformer`的 。

**Example 1.x 中 Amazon S3 `getObject`操作的**  

```
S3Object o = s3.getObject(bucket, key);
S3ObjectInputStream s3is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream(new File(key));
```

**Example 2.x 中的 Amazon S3 `getObject`操作**  

```
s3client.getObject(GetObjectRequest.builder().bucket(bucket).key(key).build(),
		ResponseTransformer.toFile(Paths.get("key")));
```

在適用於 Java 的 SDK 2.x 中，串流回應操作具有將回應載入記憶體`AsBytes`的方法，並簡化記憶體中的常見類型轉換。