- All Implemented Interfaces:
CompletionStage<MultiPartFormData.Parts>
,Future<MultiPartFormData.Parts>
A CompletableFuture
that is completed when a multipart/form-data content
has been parsed asynchronously from a Content.Source
via parse(Content.Source)
or from one or more Content.Chunk
s via parse(Content.Chunk)
.
Once the parsing of the multipart/form-data content completes successfully,
objects of this class are completed with a MultiPartFormData.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 formData = new MultiPartFormData(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 -> ...);
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The multipart/form-data specific content source.static class
An ordered list ofMultiPart.Part
s that can be accessed by index or by name, or iterated over.Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
completeExceptionally
(Throwable failure) Returns the default charset as specified by RFC 7578, section 4.6, that is the charset specified by the part named_charset_
.long
long
long
int
boolean
void
parse
(org.eclipse.jetty.io.Content.Chunk chunk) Parses the given chunk containing multipart/form-data bytes.parse
(org.eclipse.jetty.io.Content.Source content) Parses the given multipart/form-data content.void
setFilesDirectory
(Path filesDirectory) Sets the directory where the files uploaded in the parts will be saved.void
setMaxFileSize
(long maxFileSize) void
setMaxLength
(long maxLength) void
setMaxMemoryFileSize
(long maxMemoryFileSize) Sets the maximum memory file size in bytes, after which files will be saved in the directory specified bysetFilesDirectory(Path)
.void
setPartHeadersMaxLength
(int partHeadersMaxLength) void
setUseFilesForPartsWithoutFileName
(boolean useFilesForPartsWithoutFileName) Methods inherited from class java.util.concurrent.CompletableFuture
acceptEither, acceptEitherAsync, acceptEitherAsync, allOf, anyOf, applyToEither, applyToEitherAsync, applyToEitherAsync, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, exceptionally, exceptionallyAsync, exceptionallyAsync, exceptionallyCompose, exceptionallyComposeAsync, exceptionallyComposeAsync, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, supplyAsync, supplyAsync, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenApply, thenApplyAsync, thenApplyAsync, thenCombine, thenCombineAsync, thenCombineAsync, thenCompose, thenComposeAsync, thenComposeAsync, thenRun, thenRunAsync, thenRunAsync, toCompletableFuture, toString, whenComplete, whenCompleteAsync, whenCompleteAsync
-
Constructor Details
-
MultiPartFormData
-
-
Method Details
-
getBoundary
- Returns:
- the boundary string
-
parse
Parses the given multipart/form-data content.
Returns this
MultiPartFormData
object, so that it can be used in the typical "fluent" style ofCompletableFuture
.- Parameters:
content
- the multipart/form-data content to parse- Returns:
- this
MultiPartFormData
object
-
parse
public void parse(org.eclipse.jetty.io.Content.Chunk chunk) Parses the given chunk containing multipart/form-data bytes.
One or more chunks may be passed to this method, until the parsing of the multipart/form-data content completes.
- Parameters:
chunk
- theContent.Chunk
to parse.
-
getDefaultCharset
Returns the default charset as specified by RFC 7578, section 4.6, that is the charset specified by the part named
_charset_
.If that part is not present, returns
null
.- Returns:
- the default charset specified by the
_charset_
part, or null if that part is not present
-
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
-
isUseFilesForPartsWithoutFileName
public boolean isUseFilesForPartsWithoutFileName()- Returns:
- whether parts without fileName may be stored as files
-
setUseFilesForPartsWithoutFileName
public void setUseFilesForPartsWithoutFileName(boolean useFilesForPartsWithoutFileName) - Parameters:
useFilesForPartsWithoutFileName
- whether parts without fileName may be stored as files
-
getFilesDirectory
- Returns:
- the directory where files are saved
-
setFilesDirectory
Sets the directory where the files uploaded in the parts will be saved.
- Parameters:
filesDirectory
- the directory where files are saved
-
getMaxFileSize
public long getMaxFileSize()- Returns:
- the maximum file size in bytes, or -1 for unlimited file size
-
setMaxFileSize
public void setMaxFileSize(long maxFileSize) - Parameters:
maxFileSize
- the maximum file size in bytes, or -1 for unlimited file size
-
getMaxMemoryFileSize
public long getMaxMemoryFileSize()- Returns:
- the maximum memory file size in bytes, or -1 for unlimited memory file size
-
setMaxMemoryFileSize
public void setMaxMemoryFileSize(long maxMemoryFileSize) Sets the maximum memory file size in bytes, after which files will be saved in the directory specified by
setFilesDirectory(Path)
.Use value
0
to always save the files in the directory.Use value
-1
to never save the files in the directory.- Parameters:
maxMemoryFileSize
- the maximum memory file size in bytes, or -1 for unlimited memory file size
-
getMaxLength
public long getMaxLength()- Returns:
- the maximum length in bytes of the whole multipart content, or -1 for unlimited length
-
setMaxLength
public void setMaxLength(long maxLength) - Parameters:
maxLength
- the maximum length in bytes of the whole multipart content, or -1 for unlimited length
-
completeExceptionally
- Overrides:
completeExceptionally
in classCompletableFuture<MultiPartFormData.Parts>
-