- Enclosing class:
public static interface HttpRequest.BodyPublisher extends Flow.Publisher<ByteBuffer>A
BodyPublisherconverts high-level Java objects into a flow of byte buffers suitable for sending as a request body. The class
BodyPublishersprovides implementations of many common publishers.
When sending a request that contains a body, the HTTP Client subscribes to the request's
BodyPublisherin order to receive the flow of outgoing request body data. The normal semantics of
Flow.Publisherare implemented by the HTTP Client and are expected from
BodyPublisherimplementations. Each outgoing request results in one HTTP Client
Subscribersubscribing to the
BodyPublisherin order to provide the sequence of byte buffers containing the request body. Instances of
ByteBufferpublished by the publisher must be allocated by the publisher, and must not be accessed after being published to the HTTP Client. These subscriptions complete normally when the request body is fully sent, and can be canceled or terminated early through error. If a request needs to be resent for any reason, then a new subscription is created which is expected to generate the same data as before.
BodyPublisherthat reports a content length of
0may not be subscribed to by the HTTP Client, as it has effectively no data to publish.
- See Also:
long contentLength()Returns the content length for this request body. May be zero if no request body being sent, greater than zero for a fixed length content, or less than zero for an unknown content length.
This method may be invoked before the publisher is subscribed to. This method may be invoked more than once by the HTTP client implementation, and MUST return the same constant value each time.
- the content length for this request body, if known