二进制数据处理更改 - AWS SDK for Java 2.x

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

二进制数据处理更改

在版本 1 中,使用 ByteBuffer 对象直接处理二进制数据。在版本 2 中,SDK 使用 SdkBytes 对象,该对象提供一种更便捷、类型更安全的方式来处理二进制数据。

您可以使用迁移工具自动将 SdkBytes 转换为 ByteBuffer,也可以通过在返回的 SdkBytes 对象上调用 asByteBuffer() 来手动转换参数。

例 - 在版本 1 中从消息属性获取二进制数据
// Get binary data from a message attribute MessageAttributeValue messageAttributeValue = new MessageAttributeValue(); ByteBuffer binaryValue = messageAttributeValue.getBinaryValue(); String binaryString = new String(messageAttributeValue.getBinaryValue().array());
例 - 在版本 2 中从消息属性获取二进制数据
// Get binary data from a message attribute MessageAttributeValue messageAttributeValue = MessageAttributeValue.builder().build(); ByteBuffer binaryValue = messageAttributeValue.binaryValue().asByteBuffer(); String binaryString = new String(messageAttributeValue.binaryValue().asByteBuffer().array());