Class ContentPublisher

java.lang.Object
gov.usgs.earthquake.aws.ContentPublisher
All Implemented Interfaces:
HttpRequest.BodyPublisher, Flow.Publisher<ByteBuffer>

public class ContentPublisher extends Object implements HttpRequest.BodyPublisher
A simple publisher that wraps an InputStreamPublisher for primary implementation, but overrides the contentLength method since this value is actually known for Product Content. This class is meant to be used by the java.net.http.HttpRequest as a BodyPublisher for product content. Typically this might be used for PUT or POST requests and was specifically designed to work witht AWS S3 presigned URL file uploads. This is necessary because we do not want to buffer [potentially large] product content in memory, thus streaming is desired. The default streaming publisher cannot know the content length ahead of time and thus uses a `Transfer-Encoding: chunked` header, but the presigned URLs do not support this. By using knowledge of the Content to set the content length value, a `Content-Length: LENGTH` header is set and the presigned URLs work as expected. This is implemented in this way ("has-a" vs "extends") because the parent class (InputStreamPublisher) is a Java internal from which we cannot extend directly.
  • Constructor Details

    • ContentPublisher

      public ContentPublisher(Content content)
      Create a new ContentPublisher
      Parameters:
      content - The product content to be published
  • Method Details

    • subscribe

      public void subscribe(Flow.Subscriber<? super ByteBuffer> subscriber)
      Subscribes the given subscriber to this publisher. Implementation is delegated to internal InputStreamPublisher.
      Specified by:
      subscribe in interface Flow.Publisher<ByteBuffer>
      Parameters:
      subscriber - The object requesting to be subscribed to this publisher
    • contentLength

      public long contentLength()
      Returns the total content length to be published.
      Specified by:
      contentLength in interface HttpRequest.BodyPublisher
      Returns:
      The total content length