Package software.amazon.awssdk.core
Class BytesWrapper
- java.lang.Object
-
- software.amazon.awssdk.core.BytesWrapper
-
- Direct Known Subclasses:
ResponseBytes
,SdkBytes
public abstract class BytesWrapper extends Object
A base class forSdkBytes
andResponseBytes
that enables retrieving an underlying byte array as multiple different types, like a byte buffer (viaasByteBuffer()
, or a string (viaasUtf8String()
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
asByteArray()
byte[]
asByteArrayUnsafe()
ByteBuffer
asByteBuffer()
ContentStreamProvider
asContentStreamProvider()
InputStream
asInputStream()
String
asString(Charset charset)
Retrieve the output as a string.String
asUtf8String()
boolean
equals(Object o)
int
hashCode()
-
-
-
Method Detail
-
asByteBuffer
public final ByteBuffer 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:
to prevent creating an additional array copy.
-
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:
to prevent creating an additional array copy safely.
-
asString
public final String asString(Charset charset) throws UncheckedIOException
Retrieve the output as a string.- Parameters:
charset
- The charset of the string.- Returns:
- The output as a string.
- Throws:
UncheckedIOException
- with aCharacterCodingException
as the cause if the bytes cannot be encoded using the provided charset
-
asUtf8String
public final String asUtf8String() throws UncheckedIOException
- Returns:
- The output as a utf-8 encoded string.
- Throws:
UncheckedIOException
- with aCharacterCodingException
as the cause if the bytes cannot be encoded as UTF-8.
-
asInputStream
public final InputStream asInputStream()
- Returns:
- The output as an input stream. This stream will not need to be closed.
-
asContentStreamProvider
public final ContentStreamProvider asContentStreamProvider()
- Returns:
- The output as a
ContentStreamProvider
.
-
-