Class BytesWrapper

java.lang.Object
software.amazon.awssdk.core.BytesWrapper
Direct Known Subclasses:
ResponseBytes, SdkBytes

public abstract class BytesWrapper extends Object
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 Details

    • 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:
    • 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

      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 a CharacterCodingException 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 a CharacterCodingException 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.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object