Class MultiPart.AbstractContentSource

java.lang.Object
org.eclipse.jetty.http.MultiPart.AbstractContentSource
All Implemented Interfaces:
Closeable, AutoCloseable, org.eclipse.jetty.io.Content.Source
Direct Known Subclasses:
MultiPartByteRanges.ContentSource, MultiPartFormData.ContentSource
Enclosing class:
MultiPart

public abstract static class MultiPart.AbstractContentSource extends Object implements org.eclipse.jetty.io.Content.Source, Closeable

An asynchronous Content.Source where MultiPart.Parts can be added to it to form a multipart content.

When this Content.Source is read, it will produce the bytes (including boundary separators) in the multipart format.

Subclasses should override customizePartHeaders(Part) to produce the right part headers depending on the specific multipart subtype (for example, multipart/form-data or multipart/byteranges, etc.).

Typical asynchronous usage is the following:


 // Create a ContentSource subclass.
 ContentSource source = ...;

 // Add parts to the ContentSource.
 source.addPart(new ByteBufferPart());
 source.addPart(new PathPart());

 // Close the ContentSource to signal
 // that no more parts will be added.
 source.close();

 // The Sink where this ContentSource is written to.
 Content.Sink sink = ...;

 // Copy this ContentSource to the Sink.
 Content.copy(source, sink, Callback.from(...));
 

Reading from ContentSource may be performed at any time, even if not all the parts have been added yet.

Adding parts and calling close() may be done asynchronously from other threads.

Eventually, reading from ContentSource will produce a last chunk when all the parts have been added and this ContentSource has been closed.