Package com.sodius.mdw.server.utils
Class MultipartUtils
- java.lang.Object
-
- com.sodius.mdw.server.utils.MultipartUtils
-
public final class MultipartUtils extends Object
Provides utilities to handle MIME parts.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.mail.MultipartcreateMultipart(InputStream content, String contentType)Instantiates aMultipartobject extracting content from the specified stream and 'Content-Type' header.static javax.mail.BodyPartgetBodyPart(javax.mail.Multipart multipart, String inputName)Returns the part matching the specified 'name' attribute in the 'Content-Disposition' header.static StringgetContentDispositionAttribute(javax.mail.Part part, String name)Returns the value of the specified attribute name in the part 'Content-Disposition' header.static StringgetFileName(javax.mail.Part part)Return the 'filename' attribute referenced in the 'Content-Disposition' header of the part.static javax.mail.BodyPartgetFilePart(javax.mail.Multipart multipart)Returns the first part that contains a file content.static StringgetStringContent(javax.mail.Part part)Returns the part content as aString.static booleanisFilePart(javax.mail.Part part)Determines whether the part contains file content.static booleanisMultipart(String contentType)Determines whether the specified HTTP Content-Type is"multipart/form-data".
-
-
-
Method Detail
-
isMultipart
public static boolean isMultipart(String contentType)
Determines whether the specified HTTP Content-Type is"multipart/form-data".- Parameters:
contentType- a HTTP Content-Type header value (may benull).- Returns:
trueif the Content-Type is"multipart/form-data",falseotherwise.
-
getFilePart
public static javax.mail.BodyPart getFilePart(javax.mail.Multipart multipart) throws javax.mail.MessagingExceptionReturns the first part that contains a file content.- Parameters:
multipart- a multipart.- Returns:
- the first part that contains a file content.
- Throws:
javax.mail.MessagingException- if the multipart content cannot be read.- See Also:
isFilePart(Part)
-
isFilePart
public static boolean isFilePart(javax.mail.Part part) throws javax.mail.MessagingExceptionDetermines whether the part contains file content.- Parameters:
part- the part.- Returns:
trueif the part contains a 'Content-Disposition' header that has a 'filename' attribute,falseotherwise.- Throws:
javax.mail.MessagingException- if the part content cannot be read.
-
getFileName
public static String getFileName(javax.mail.Part part) throws javax.mail.MessagingException
Return the 'filename' attribute referenced in the 'Content-Disposition' header of the part.- Parameters:
part- the part.- Returns:
- the 'filename' attribute of the part 'Content-Disposition' header,
nullif none. - Throws:
javax.mail.MessagingException- if the part content cannot be read.- See Also:
isFilePart(Part)
-
getBodyPart
public static javax.mail.BodyPart getBodyPart(javax.mail.Multipart multipart, String inputName) throws javax.mail.MessagingExceptionReturns the part matching the specified 'name' attribute in the 'Content-Disposition' header.- Parameters:
multipart- the multipart.inputName- the 'name' attribute to look for.- Returns:
- the part matching the specified 'name' attribute in the 'Content-Disposition' header,
nullif none. - Throws:
javax.mail.MessagingException- if the multipart content cannot be read.
-
getContentDispositionAttribute
public static String getContentDispositionAttribute(javax.mail.Part part, String name) throws javax.mail.MessagingException
Returns the value of the specified attribute name in the part 'Content-Disposition' header.- Parameters:
part- the part.name- the attribute name to look for.- Returns:
- the value of the specified attribute name in the part 'Content-Disposition' header,
nullif none. - Throws:
javax.mail.MessagingException- if the part content cannot be read.
-
getStringContent
public static String getStringContent(javax.mail.Part part) throws IOException, javax.mail.MessagingException
Returns the part content as aString. The part content is decoded usingUTF-8.- Parameters:
part- the part.- Returns:
- the content of the part as a String.
- Throws:
IOException- if the part content cannot be read.javax.mail.MessagingException- if the part content cannot be read.
-
createMultipart
public static javax.mail.Multipart createMultipart(InputStream content, String contentType) throws IOException, javax.mail.MessagingException
Instantiates aMultipartobject extracting content from the specified stream and 'Content-Type' header.- Parameters:
content- the stream from where multipart content must be read.contentType- the multipart 'Content-Type'.- Returns:
- a
Multipartinstance. - Throws:
IOException- if the multipart content cannot be read.javax.mail.MessagingException- if the multipart content cannot be read.
-
-