A CompletableFuture that is completed when a multipart/form-data content
has been parsed asynchronously from a Content..
Once the parsing of the multipart/form-data content completes successfully,
objects of this class are completed with a Parts object.
Objects of this class may be configured to save multipart files in a configurable directory, and configure the max size of such files, etc.
Typical usage:
// Some headers that include Content-Type.
HttpFields headers = ...;
String boundary = MultiPart.extractBoundary(headers.get(HttpHeader.CONTENT_TYPE));
// Some multipart/form-data content.
Content.Source content = ...;
// Create and configure MultiPartFormData.
MultiPartFormData.Parser formData = new MultiPartFormData.Parser(boundary);
// Where to store the files.
formData.setFilesDirectory(Path.of("/tmp"));
// Max 1 MiB files.
formData.setMaxFileSize(1024 * 1024);
// Parse the content.
formData.parse(content)
// When complete, use the parts.
.thenAccept(parts -> ...);
Parts
| Modifier and Type | Class and Description |
|---|---|
| public static class | MultiPartFormData.ContentSource
The multipart/form-data specific content source. |
| public static class | |
| public static class | MultiPartFormData.Parts
An ordered list of |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static CompletableFuture | from(Attributes attributes, String boundary, Function<MultiPartFormData.
Deprecated
for removal since 12.0.6. use
from(Attributes, ComplianceViolation. instead.
|
| public static CompletableFuture | from(Attributes attributes, ComplianceViolation.
|
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| MultiPartFormData | back to summary |
|---|---|
| private MultiPartFormData() | |
| from | back to summary |
|---|---|
| public static CompletableFuture Deprecated for removal since 12.0.6. use
| |
| from | back to summary |
|---|---|
| public static CompletableFuture | |
The multipart/form-data specific content source.
MultiPart.AbstractContentSource
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected HttpFields |
| ContentSource | back to summary |
|---|---|
| public ContentSource(String boundary) | |
| customizePartHeaders | back to summary |
|---|---|
| protected HttpFields customizePartHeaders(MultiPart. Overrides org. | |
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private ComplianceViolation. | |
| private Path | |
| private long | |
| private final MultiPartFormData. | |
| private long | |
| private long | |
| private long | |
| private final MultiPart. | |
| private MultiPartFormData. | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private Path | |
| public String | |
| public Charset | Returns: the default charset specified by the_charset_ part,
or null if that part is not presentReturns the default charset as specified by
RFC 7578, section 4.6,
that is the charset specified by the part named |
| public Path | |
| public long | |
| public long | Returns: the maximum length in bytes of the whole multipart content, or -1 for unlimited length
|
| public long | Returns: the maximum memory file size in bytes, or -1 for unlimited memory file size
|
| public long | |
| public int | Returns: the max length of aMultiPart. headers, in bytes, or -1 for unlimited length
|
| pack-priv int | |
| public boolean | |
| public CompletableFuture | |
| public void | setFilesDirectory(Path
the directory where files are saved filesDirectory)Sets the directory where the files uploaded in the parts will be saved. |
| public void | |
| public void | setMaxLength(long
the maximum length in bytes of the whole multipart content, or -1 for unlimited length maxLength)
|
| public void | setMaxMemoryFileSize(long
the maximum memory file size in bytes, or -1 for unlimited memory file size maxMemoryFileSize)Sets the maximum memory file size in bytes, after which files will be saved
in the directory specified by |
| public void | setMaxParts(long
the maximum number of parts that can be parsed from the multipart content. maxParts)
|
| public void | setPartHeadersMaxLength(int
the max length of a partHeadersMaxLength)MultiPart. headers, in bytes, or -1 for unlimited length
|
| public void | setUseFilesForPartsWithoutFileName(boolean
whether parts without fileName may be stored as files useFilesForPartsWithoutFileName)
|
| complianceViolationListener | back to summary |
|---|---|
| private ComplianceViolation. | |
| filesDirectory | back to summary |
|---|---|
| private Path filesDirectory | |
| length | back to summary |
|---|---|
| private long length | |
| listener | back to summary |
|---|---|
| private final MultiPartFormData. | |
| maxFileSize | back to summary |
|---|---|
| private long maxFileSize | |
| maxLength | back to summary |
|---|---|
| private long maxLength | |
| maxMemoryFileSize | back to summary |
|---|---|
| private long maxMemoryFileSize | |
| parser | back to summary |
|---|---|
| private final MultiPart. | |
| parts | back to summary |
|---|---|
| private MultiPartFormData. | |
| useFilesForPartsWithoutFileName | back to summary |
|---|---|
| private boolean useFilesForPartsWithoutFileName | |
| Parser | back to summary |
|---|---|
| public Parser(String boundary) | |
| Parser | back to summary |
|---|---|
| public Parser(String boundary, ComplianceViolation. | |
| findFilesDirectory | back to summary |
|---|---|
| private Path findFilesDirectory() | |
| getBoundary | back to summary |
|---|---|
public String getBoundary()
| |
| getDefaultCharset | back to summary |
|---|---|
| public Charset getDefaultCharset() Returns the default charset as specified by
RFC 7578, section 4.6,
that is the charset specified by the part named If that part is not present, returns
| |
| getFilesDirectory | back to summary |
|---|---|
public Path getFilesDirectory()
| |
| getMaxFileSize | back to summary |
|---|---|
public long getMaxFileSize()
| |
| getMaxLength | back to summary |
|---|---|
public long getMaxLength()
| |
| getMaxMemoryFileSize | back to summary |
|---|---|
public long getMaxMemoryFileSize()
| |
| getMaxParts | back to summary |
|---|---|
public long getMaxParts()
| |
| getPartHeadersMaxLength | back to summary |
|---|---|
public int getPartHeadersMaxLength()
| |
| getPartsSize | back to summary |
|---|---|
| pack-priv int getPartsSize() | |
| isUseFilesForPartsWithoutFileName | back to summary |
|---|---|
public boolean isUseFilesForPartsWithoutFileName()
| |
| parse | back to summary |
|---|---|
| public CompletableFuture | |
| setFilesDirectory | back to summary |
|---|---|
| public void setFilesDirectory(Path filesDirectory) Sets the directory where the files uploaded in the parts will be saved.
| |
| setMaxFileSize | back to summary |
|---|---|
public void setMaxFileSize(long maxFileSize)
| |
| setMaxLength | back to summary |
|---|---|
public void setMaxLength(long maxLength)
| |
| setMaxMemoryFileSize | back to summary |
|---|---|
| public void setMaxMemoryFileSize(long maxMemoryFileSize) Sets the maximum memory file size in bytes, after which files will be saved
in the directory specified by Use value Use value
| |
| setMaxParts | back to summary |
|---|---|
public void setMaxParts(long maxParts)
| |
| setPartHeadersMaxLength | back to summary |
|---|---|
public void setPartHeadersMaxLength(int partHeadersMaxLength)
| |
| setUseFilesForPartsWithoutFileName | back to summary |
|---|---|
public void setUseFilesForPartsWithoutFileName(boolean useFilesForPartsWithoutFileName)
| |
| Modifier and Type | Field and Description |
|---|---|
| private Throwable | |
| private SeekableByteChannel | |
| private Path | |
| private long | |
| private final AutoLock | |
| private long | |
| private final List | |
| private final List |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| private void | |
| private boolean | |
| private void | |
| private SeekableByteChannel | |
| pack-priv Charset | |
| pack-priv int | |
| private boolean | |
| public void | onComplete()
Overrides default org. Callback method invoked when the whole multipart content has been parsed. |
| public void | onFailure(Throwable
the failure cause failure)Overrides default org. Callback method invoked when the parser cannot parse the multipart content. |
| public void | onPart(String
the part name name, String the part fileName fileName, HttpFields the part headers headers)Implements abstract org. Callback method invoked when a |
| public void | onPartContent(Content.
the part content chunk chunkOverrides default org. Callback method invoked when a part content |
| private void |
| failure | back to summary |
|---|---|
| private Throwable failure | |
| fileChannel | back to summary |
|---|---|
| private SeekableByteChannel fileChannel | |
| filePath | back to summary |
|---|---|
| private Path filePath | |
| fileSize | back to summary |
|---|---|
| private long fileSize | |
| lock | back to summary |
|---|---|
| private final AutoLock lock | |
| memoryFileSize | back to summary |
|---|---|
| private long memoryFileSize | |
| partChunks | back to summary |
|---|---|
| private final List<Content. | |
| parts | back to summary |
|---|---|
| private final List<MultiPart. | |
| PartsListener | back to summary |
|---|---|
| private PartsListener() | |
| close | back to summary |
|---|---|
| private void close() | |
| createFileChannel | back to summary |
|---|---|
| private void createFileChannel() | |
| delete | back to summary |
|---|---|
| private void delete() | |
| ensureFileChannel | back to summary |
|---|---|
| private boolean ensureFileChannel() | |
| fail | back to summary |
|---|---|
| private void fail(Throwable cause) | |
| fileChannel | back to summary |
|---|---|
| private SeekableByteChannel fileChannel() | |
| getDefaultCharset | back to summary |
|---|---|
| pack-priv Charset getDefaultCharset() | |
| getPartsSize | back to summary |
|---|---|
| pack-priv int getPartsSize() | |
| isFailed | back to summary |
|---|---|
| private boolean isFailed() | |
| onComplete | back to summary |
|---|---|
| public void onComplete() Overrides default org. Doc from org. Callback method invoked when the whole multipart content has been parsed.
| |
| onFailure | back to summary |
|---|---|
| public void onFailure(Throwable failure) Overrides default org. Doc from org. Callback method invoked when the parser cannot parse the multipart content. | |
| onPart | back to summary |
|---|---|
| public void onPart(String name, String fileName, HttpFields headers) Implements abstract org. Doc from org. Callback method invoked when a
| |
| onPartContent | back to summary |
|---|---|
| public void onPartContent(Content. Overrides default org. Doc from org. Callback method invoked when a part content The | |
| write | back to summary |
|---|---|
| private void write(ByteBuffer buffer) throws Exception | |
An ordered list of MultiPart.s that can
be accessed by index or by name, or iterated over.
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements java. |
| public MultiPart. | Returns: theMultiPart.Part at the given indexthe index of the index)MultiPart.Part to returnReturns the |
| public List | Returns: all theMultiPart.Parts with the given namethe name)MultiPart.Parts nameReturns all the |
| public MultiPart. | Returns: the firstMultiPart.Part with the given name, or nullthe name)MultiPart.Part nameReturns the first |
| public Iterator | |
| public int |
| parts | back to summary |
|---|---|
| private final List<MultiPart. | |
| Parts | back to summary |
|---|---|
| private Parts(List<MultiPart. | |
| close | back to summary |
|---|---|
| public void close() Implements java. Doc from java. Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. As noted in
| |
| get | back to summary |
|---|---|
| public MultiPart. Returns the | |
| getAll | back to summary |
|---|---|
| public List Returns all the | |
| getFirst | back to summary |
|---|---|
| public MultiPart. Returns the first | |
| iterator | back to summary |
|---|---|
| public Iterator Implements java. Doc from java. Returns an iterator over elements of type | |
| size | back to summary |
|---|---|
public int size()
| |