Interface ContentStreamProvider
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@SdkPublicApi @FunctionalInterface public interface ContentStreamProvider
Provides the content stream of a request.Each call to the
newStream()method must result in a stream whose position is at the beginning of the content. Implementations may return a new stream or the same stream for each call. If returning a new stream, the implementation must ensure toclose()and free any resources acquired by the previous stream. The last stream returned bynewStream()} will be closed by the SDK.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classContentStreamProvider.ProviderType
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static ContentStreamProviderfromByteArray(byte[] bytes)CreateContentStreamProviderfrom a byte array.static ContentStreamProviderfromByteArrayUnsafe(byte[] bytes)CreateContentStreamProviderfrom a byte array without copying the contents of the byte array.static ContentStreamProviderfromInputStream(InputStream inputStream)Create aContentStreamProviderfrom an input stream.static ContentStreamProviderfromInputStreamSupplier(Supplier<InputStream> inputStreamSupplier)CreateContentStreamProviderfrom an input stream supplier.static ContentStreamProviderfromString(String string, Charset charset)CreateContentStreamProviderfrom a string, using the provided charset.static ContentStreamProviderfromUtf8String(String string)CreateContentStreamProviderfrom a string, using the UTF-8 charset.default Stringname()Each ContentStreamProvider should return a well-formed name that can be used to identify the implementation.InputStreamnewStream()
-
-
-
Method Detail
-
fromByteArray
static ContentStreamProvider fromByteArray(byte[] bytes)
CreateContentStreamProviderfrom a byte array. This will copy the contents of the byte array.
-
fromByteArrayUnsafe
static ContentStreamProvider fromByteArrayUnsafe(byte[] bytes)
CreateContentStreamProviderfrom a byte array without copying the contents of the byte array. This introduces concurrency risks, allowing the caller to modify the byte array stored in thisContentStreamProviderimplementation.As the method name implies, this is unsafe. Use
fromByteArray(byte[])unless you're sure you know the risks.
-
fromString
static ContentStreamProvider fromString(String string, Charset charset)
CreateContentStreamProviderfrom a string, using the provided charset.
-
fromUtf8String
static ContentStreamProvider fromUtf8String(String string)
CreateContentStreamProviderfrom a string, using the UTF-8 charset.
-
fromInputStream
static ContentStreamProvider fromInputStream(InputStream inputStream)
Create aContentStreamProviderfrom an input stream.If the provided input stream supports mark/reset, the stream will be marked with a 128Kb read limit and reset each time
newStream()is invoked. If the provided input stream does not support mark/reset,newStream()will return the provided stream once, but fail subsequent calls. To create new streams when needed instead of using mark/reset, seefromInputStreamSupplier(Supplier).
-
fromInputStreamSupplier
static ContentStreamProvider fromInputStreamSupplier(Supplier<InputStream> inputStreamSupplier)
CreateContentStreamProviderfrom an input stream supplier. Each time a new stream is retrieved from this content stream provider, the last one returned will be closed.
-
newStream
InputStream newStream()
- Returns:
- The content stream.
-
name
default String name()
Each ContentStreamProvider should return a well-formed name that can be used to identify the implementation. The stream name should only include alphanumeric characters.- Returns:
- String containing the identifying name of this ContentStreamProvider implementation.
-
-