public final class MultipartUtils extends Object
Modifier and Type | Method and Description |
---|---|
static Multipart |
createMultipart(InputStream content,
String contentType)
Instantiates a
Multipart object extracting content from the specified stream and 'Content-Type' header. |
static BodyPart |
getBodyPart(Multipart multipart,
String inputName)
Returns the part matching the specified 'name' attribute in the 'Content-Disposition' header.
|
static String |
getContentDispositionAttribute(Part part,
String name)
Returns the value of the specified attribute name in the part 'Content-Disposition' header.
|
static String |
getFileName(Part part)
Return the 'filename' attribute referenced in the 'Content-Disposition' header of the part.
|
static BodyPart |
getFilePart(Multipart multipart)
Returns the first part that contains a file content.
|
static String |
getStringContent(Part part)
Returns the part content as a
String . |
static boolean |
isFilePart(Part part)
Determines whether the part contains file content.
|
static boolean |
isMultipart(String contentType)
Determines whether the specified HTTP Content-Type is
"multipart/form-data" . |
public static boolean isMultipart(String contentType)
"multipart/form-data"
.contentType
- a HTTP Content-Type header value (may be null
).true
if the Content-Type is "multipart/form-data"
, false
otherwise.public static BodyPart getFilePart(Multipart multipart) throws MessagingException
multipart
- a multipart.MessagingException
- if the multipart content cannot be read.isFilePart(Part)
public static boolean isFilePart(Part part) throws MessagingException
part
- the part.true
if the part contains
a 'Content-Disposition' header that has a 'filename' attribute, false
otherwise.MessagingException
- if the part content cannot be read.public static String getFileName(Part part) throws MessagingException
part
- the part.null
if none.MessagingException
- if the part content cannot be read.isFilePart(Part)
public static BodyPart getBodyPart(Multipart multipart, String inputName) throws MessagingException
multipart
- the multipart.inputName
- the 'name' attribute to look for.null
if none.MessagingException
- if the multipart content cannot be read.public static String getContentDispositionAttribute(Part part, String name) throws MessagingException
part
- the part.name
- the attribute name to look for.null
if none.MessagingException
- if the part content cannot be read.public static String getStringContent(Part part) throws IOException, MessagingException
String
.
The part content is decoded using UTF-8
.part
- the part.IOException
- if the part content cannot be read.MessagingException
- if the part content cannot be read.public static Multipart createMultipart(InputStream content, String contentType) throws IOException, MessagingException
Multipart
object extracting content from the specified stream and 'Content-Type' header.content
- the stream from where multipart content must be read.contentType
- the multipart 'Content-Type'.Multipart
instance.IOException
- if the multipart content cannot be read.MessagingException
- if the multipart content cannot be read.