Class BytesWrapper
java.lang.Object
software.amazon.awssdk.core.BytesWrapper
- Direct Known Subclasses:
ResponseBytes,SdkBytes
A base class for
SdkBytes and ResponseBytes that enables retrieving an underlying byte array as multiple
different types, like a byte buffer (via asByteBuffer(), or a string (via asUtf8String().-
Method Summary
Modifier and TypeMethodDescriptionfinal byte[]final byte[]final ByteBufferfinal ContentStreamProviderfinal InputStreamfinal StringRetrieve the output as a string.final StringbooleaninthashCode()
-
Method Details
-
asByteBuffer
- Returns:
- The output as a read-only byte buffer.
-
asByteArray
public final byte[] asByteArray()- Returns:
- A copy of the output as a byte array.
- See Also:
-
asByteArrayUnsafe
public final byte[] asByteArrayUnsafe()- Returns:
- The output as a byte array. This does not create a copy of the underlying byte array. This introduces
concurrency risks, allowing: (1) the caller to modify the byte array stored in this object implementation AND
(2) the original creator of this object, if they created it using the unsafe method.
Consider using
asByteBuffer(), which is a safer method to avoid an additional array copy because it does not provide a way to modify the underlying buffer. As the method name implies, this is unsafe. If you're not sure, don't use this. The only guarantees given to the user of this method is that the SDK itself won't modify the underlying byte array. - See Also:
-
asString
Retrieve the output as a string.- Parameters:
charset- The charset of the string.- Returns:
- The output as a string.
- Throws:
UncheckedIOException- with aCharacterCodingExceptionas the cause if the bytes cannot be encoded using the provided charset
-
asUtf8String
- Returns:
- The output as a utf-8 encoded string.
- Throws:
UncheckedIOException- with aCharacterCodingExceptionas the cause if the bytes cannot be encoded as UTF-8.
-
asInputStream
- Returns:
- The output as an input stream. This stream will not need to be closed.
-
asContentStreamProvider
- Returns:
- The output as a
ContentStreamProvider.
-
equals
-
hashCode
-