Class MultiPart.Part
- All Implemented Interfaces:
Closeable, AutoCloseable, Content.Source.Factory
- Direct Known Subclasses:
MultiPart.ByteBufferPart, MultiPart.ChunksPart, MultiPart.ContentSourcePart, MultiPart.PathPart, MultiPartByteRanges.Part
- Enclosing class:
MultiPart
A single part of a multipart content.
A part has an optional name, an optional fileName, optional headers and an optional content.
-
Constructor Summary
ConstructorsConstructorDescriptionPart(String name, String fileName, HttpFields fields) Deprecated, for removal: This API element is subject to removal in a future version.Part(ByteBufferPool.Sized bufferPool, long first, long length, String name, String fileName, HttpFields fields) Part(ByteBufferPool.Sized bufferPool, String name, String fileName, HttpFields fields) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voiddelete()voidgetContentAsString(Charset defaultCharset) Returns the content of this part as a string.Returns the content of this part as aContent.Source.Returns the file name of this part, as specified by theHttpHeader.CONTENT_DISPOSITION'sfilenameparameter.longgetName()Returns the name of this part, as specified by theHttpHeader.CONTENT_DISPOSITION'snameparameter.Deprecated, for removal: This API element is subject to removal in a future version.overridenewContentSource(ByteBufferPool.Sized, long, long)instead.newContentSource(ByteBufferPool.Sized bufferPool, long first, long length) Creates a newContent.Source.voidWrites the content of this part to the given path.
-
Constructor Details
-
Part
@Deprecated(since="12.0.20", forRemoval=true) public Part(String name, String fileName, HttpFields fields) Deprecated, for removal: This API element is subject to removal in a future version. -
Part
-
Part
public Part(ByteBufferPool.Sized bufferPool, long first, long length, String name, String fileName, HttpFields fields)
-
-
Method Details
-
getName
Returns the name of this part, as specified by the
HttpHeader.CONTENT_DISPOSITION'snameparameter.While the
nameparameter is mandatory per RFC 7578, older HTTP clients may not send it.- Returns:
- the name of this part, or
nullif there is no name
-
getFileName
Returns the file name of this part, as specified by the
HttpHeader.CONTENT_DISPOSITION'sfilenameparameter.While the
filenameparameter is mandatory per RFC 7578 when uploading files, older HTTP clients may not send it.The file name may be absent if the part is not a file upload.
- Returns:
- the file name of this part, or
nullif there is no file name
-
getContentSource
Returns the content of this part as a
Content.Source.Calling this method multiple times will return the same instance, which can only be consumed once.
The content type and content encoding are specified in this part's
headers.The content encoding may be specified by the part named
_charset_, as specified in RFC 7578, section 4.6.- Returns:
- the content of this part
- See Also:
-
newContentSource
Deprecated, for removal: This API element is subject to removal in a future version.overridenewContentSource(ByteBufferPool.Sized, long, long)instead.Returns the content of this part as a new
Content.SourceIf the content is reproducible, invoking this method multiple times will return a different independent instance for every invocation.
If the content is not reproducible, subsequent calls to this method will return null.
The content type and content encoding are specified in this part's
headers.The content encoding may be specified by the part named
_charset_, as specified in RFC 7578, section 4.6.- Returns:
- the content of this part as a new
Content.Sourceor null if the content cannot be consumed multiple times. - See Also:
-
newContentSource
Creates a newContent.Source.Returns the content of this part as a new
Content.SourceIf the content is reproducible, invoking this method multiple times will return a different independent instance for every invocation.
If the content is not reproducible, subsequent calls to this method will return null.
The content type and content encoding are specified in this part's
headers.The content encoding may be specified by the part named
_charset_, as specified in RFC 7578, section 4.6.- Specified by:
newContentSourcein interfaceContent.Source.Factory- Parameters:
bufferPool- theByteBufferPool.Sizedto get buffers from.nullmeans allocate new buffers as needed.first- the first byte of the resource to start from.length- the length of the content to make available, -1 for the full length.- Returns:
- a
Content.Source. - See Also:
-
getLength
public long getLength() -
getContentAsString
Returns the content of this part as a string.
The charset used to decode the bytes is:
- the
charsetparameter of theHttpHeader.CONTENT_TYPEheader, if non-null; - otherwise, the given
defaultCharsetparameter, if non-null; - otherwise, UTF-8.
- Parameters:
defaultCharset- the charset to use to decode the bytes, if thecharsetparameter of theContent-Typeheader is missing- Returns:
- the content of this part as a string
- the
-
getHeaders
- Returns:
- the headers associated with this part
-
writeTo
Writes the content of this part to the given path.
- Parameters:
path- the Path to write this part's content to- Throws:
IOException- if the write fails
-
delete
- Throws:
IOException
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
fail
-
Part(ByteBufferPool.Sized, String, String, HttpFields)instead.