- 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.Chunks 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 classThe multipart/form-data specific content source.classAn ordered list ofMultiPart.Parts that can be accessed by index or by name, or iterated over.Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTaskNested classes/interfaces inherited from interface java.util.concurrent.Future
Future.State -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancompleteExceptionally(Throwable failure) Returns the default charset as specified by RFC 7578, section 4.6, that is the charset specified by the part named_charset_.longlonglonglongintbooleanvoidparse(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.voidsetFilesDirectory(Path filesDirectory) Sets the directory where the files uploaded in the parts will be saved.voidsetMaxFileSize(long maxFileSize) voidsetMaxLength(long maxLength) voidsetMaxMemoryFileSize(long maxMemoryFileSize) Sets the maximum memory file size in bytes, after which files will be saved in the directory specified bysetFilesDirectory(Path).voidsetMaxParts(long maxParts) voidsetPartHeadersMaxLength(int partHeadersMaxLength) voidsetUseFilesForPartsWithoutFileName(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, exceptionNow, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, handle, handleAsync, handleAsync, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, resultNow, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAsync, runAsync, state, 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
MultiPartFormDataobject, so that it can be used in the typical "fluent" style ofCompletableFuture.- Parameters:
content- the multipart/form-data content to parse- Returns:
- this
MultiPartFormDataobject
-
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.Chunkto 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.Partheaders, in bytes, or -1 for unlimited length
-
setPartHeadersMaxLength
public void setPartHeadersMaxLength(int partHeadersMaxLength) - Parameters:
partHeadersMaxLength- the max length of aMultiPart.Partheaders, 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
0to always save the files in the directory.Use value
-1to 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
-
getMaxParts
public long getMaxParts()- Returns:
- the maximum number of parts that can be parsed from the multipart content.
-
setMaxParts
public void setMaxParts(long maxParts) - Parameters:
maxParts- the maximum number of parts that can be parsed from the multipart content.
-
completeExceptionally
- Overrides:
completeExceptionallyin classCompletableFuture<MultiPartFormData.Parts>
-