- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.eclipse.jetty.io.Content.Source
- Direct Known Subclasses:
MultiPartByteRanges.ContentSource
,MultiPartFormData.ContentSource
- Enclosing class:
MultiPart
An asynchronous Content.Source
where MultiPart.Part
s 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
addPart
(MultiPart.Part part) Adds, if possible, the givenMultiPart.Part
to thisContentSource
.void
close()
Closes thisContentSource
so that no more parts may be added.protected HttpFields
void
void
long
int
org.eclipse.jetty.io.Content.Chunk
read()
void
setPartHeadersMaxLength
(int partHeadersMaxLength) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.io.Content.Source
rewind
-
Constructor Details
-
AbstractContentSource
-
-
Method Details
-
getBoundary
- Returns:
- the boundary string
-
getPartHeadersMaxLength
public int getPartHeadersMaxLength()- Returns:
- the max length of a
MultiPart.Part
headers, in bytes, or -1 for unlimited length
-
setPartHeadersMaxLength
public void setPartHeadersMaxLength(int partHeadersMaxLength) - Parameters:
partHeadersMaxLength
- the max length of aMultiPart.Part
headers, in bytes, or -1 for unlimited length
-
addPart
Adds, if possible, the given
MultiPart.Part
to thisContentSource
.Part
s may be added until thisContentSource
isclosed
.This method returns
true
if the part was added,false
if the part cannot be added because thisContentSource
is already closed, or because it has beenfailed
.- Parameters:
part
- theMultiPart.Part
to add- Returns:
- whether the part has been added
- See Also:
-
close
public void close()Closes this
ContentSource
so that no more parts may be added.Once this method is called, reading from this
ContentSource
will eventually produce a terminal multipart/form-data boundary, when all the part bytes have been read.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
getLength
public long getLength()- Specified by:
getLength
in interfaceorg.eclipse.jetty.io.Content.Source
-
read
public org.eclipse.jetty.io.Content.Chunk read()- Specified by:
read
in interfaceorg.eclipse.jetty.io.Content.Source
-
customizePartHeaders
-
demand
- Specified by:
demand
in interfaceorg.eclipse.jetty.io.Content.Source
-
fail
- Specified by:
fail
in interfaceorg.eclipse.jetty.io.Content.Source
-