Class EnvelopeWrappedSdkPublisher<T>

java.lang.Object
software.amazon.awssdk.core.internal.async.EnvelopeWrappedSdkPublisher<T>
Type Parameters:
T - The type of objects being published
All Implemented Interfaces:
org.reactivestreams.Publisher<T>, SdkPublisher<T>

public class EnvelopeWrappedSdkPublisher<T> extends Object implements SdkPublisher<T>
Publisher implementation that wraps the content of another publisher in an envelope with an optional prefix (or header) and suffix (or footer). The prefix content will be prepended to the first published object from the wrapped publisher, and the suffix content will be published when the wrapped publisher signals completion.

The envelope prefix will not be published until the wrapped publisher publishes something or is completed. The envelope suffix will not be published until the wrapped publisher is completed.

This class can be used in an asynchronous interceptor in the AWS SDK to wrap content around the incoming bytestream from a response.

A function must be supplied that can be used to concatenate the envelope content with the content being published by the wrapped publisher. Example usage: Publisher<String> wrappedPublisher = ContentEnvelopeWrappingPublisher.of(publisher, "S", "E", (s1, s2) -> s1 + s2); If publisher publishes a single string "1", wrappedPublisher will publish "S1" (prepending the envelop prefix). If publisher then publishes a second string "2", wrappedPublisher will then publish "2" (no added content). If publisher then completes, wrappedPublisher will then publish "E" and then complete.

WARNING: This publisher implementation does not comply with the complete flow spec (as it inserts data into the middle of a flow between a third-party publisher and subscriber rather than acting as a fully featured independent publisher) and therefore should only be used in a limited fashion when we have complete control over how data is being published to the publisher it wraps.

  • Method Details

    • of

      public static <T> EnvelopeWrappedSdkPublisher<T> of(org.reactivestreams.Publisher<T> wrappedPublisher, T contentPrefix, T contentSuffix, BiFunction<T,T,T> mergeContentFunction)
      Create a new publisher that wraps the content of an existing publisher.
      Type Parameters:
      T - The content type.
      Parameters:
      wrappedPublisher - The publisher who's content will be wrapped.
      contentPrefix - The content to be inserted in front of the wrapped content.
      contentSuffix - The content to be inserted at the back of the wrapped content.
      mergeContentFunction - A function that will be used to merge the inserted content into the wrapped content.
      Returns:
      A newly initialized instance of this class.
    • subscribe

      public void subscribe(org.reactivestreams.Subscriber<? super T> subscriber)
      See Publisher.subscribe(Subscriber)
      Specified by:
      subscribe in interface org.reactivestreams.Publisher<T>