Package com.opencloud.sentinel.util
Class MultipartMessageBody
- java.lang.Object
-
- com.opencloud.sentinel.util.MultipartMessageBody
-
- All Implemented Interfaces:
java.lang.Iterable<MessageBody>
public class MultipartMessageBody extends java.lang.Object implements java.lang.Iterable<MessageBody>
-
-
Constructor Summary
Constructors Constructor Description MultipartMessageBody(java.util.List<MessageBody> parts)
Creates a new multipart message body with the given parts and a default content boundary String: "multipart-content-boundary".MultipartMessageBody(java.util.List<MessageBody> parts, java.lang.String boundary)
Creates a new multipart message body with the given parts and content boundary String.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static MultipartMessageBody
decode(byte[] rawContent, java.lang.String contentType)
Decodes a message body that has a "multipart" Content-Type as per RFC2046.byte[]
encode()
Encodes this MultipartMessageBody into a byte array suitable for inclusion in a SIP message body.java.lang.String
getContentDisposition()
Convenience method, if this MultipartMessageBody only has one part, this method will return a String suitable for use as a Content-Disposition header of a SIP message bearing this MultipartMessageBody in its message body.java.lang.String
getContentType()
Returns a String suitable for use as a Content-Type header for a SIP message bearing this MultipartMessageBody in its message body.MessageBody
getPart(java.lang.String contentType)
Returns the first part in the multipart message body that has the given content type.java.util.List<MessageBody>
getPartsList()
Gives access to the list of message body parts contained in this MultipartMessageBody.boolean
hasContent()
java.util.Iterator<MessageBody>
iterator()
java.lang.String
toString()
-
-
-
Constructor Detail
-
MultipartMessageBody
public MultipartMessageBody(java.util.List<MessageBody> parts)
Creates a new multipart message body with the given parts and a default content boundary String: "multipart-content-boundary".- Parameters:
parts
- The individual content body parts in a list
-
MultipartMessageBody
public MultipartMessageBody(java.util.List<MessageBody> parts, java.lang.String boundary)
Creates a new multipart message body with the given parts and content boundary String.- Parameters:
parts
- The individual content body parts in a listboundary
- The boundary String to insert between the individual parts of the multipart content body
-
-
Method Detail
-
iterator
public java.util.Iterator<MessageBody> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<MessageBody>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getPart
public MessageBody getPart(java.lang.String contentType)
Returns the first part in the multipart message body that has the given content type.- Parameters:
contentType
- The content type of the desired message body part.- Returns:
- The found message body part, or null if one could not be found.
-
getPartsList
public java.util.List<MessageBody> getPartsList()
Gives access to the list of message body parts contained in this MultipartMessageBody. This list in not a copy, mutations will affect this MultipartMessageBody.- Returns:
- The list of message body parts in this MultipartMessageBody.
-
getContentType
public java.lang.String getContentType()
Returns a String suitable for use as a Content-Type header for a SIP message bearing this MultipartMessageBody in its message body. If this MultipartMessageBody currently has no parts, this method will return "text/plain". If this MultipartMessageBody currently has one part, this method will return the content type of that part. If this MultipartMessageBody currently has multiple parts, this method will return "multipart/mixed" with a boundary parameter.- Returns:
- A string to be used as a Content-Type header
-
getContentDisposition
public java.lang.String getContentDisposition()
Convenience method, if this MultipartMessageBody only has one part, this method will return a String suitable for use as a Content-Disposition header of a SIP message bearing this MultipartMessageBody in its message body. If this MultipartMessageBody currently has one part, this method will return the content disposition of that part. If this MultipartMessageBody currently has multiple parts, or no part, this method will return null.- Returns:
- A string to be used as a Content-Disposition header, or null
-
hasContent
public boolean hasContent()
- Returns:
- True if the list of message bodies in this MultipartMessageBody contains at least one item.
-
encode
public byte[] encode()
Encodes this MultipartMessageBody into a byte array suitable for inclusion in a SIP message body. If this MultipartMessageBody currently has no parts, this method will return an byte array of size zero. If this MultipartMessageBody currently has one part, this method will return the raw content of that part. If this MultipartMessageBody currently has multiple parts, this method will return a formatted multipart body.- Returns:
- A byte array suitable for use as a SIP message body
-
decode
public static MultipartMessageBody decode(byte[] rawContent, java.lang.String contentType) throws java.io.IOException
Decodes a message body that has a "multipart" Content-Type as per RFC2046. The caller must ensure that the message has a "multipart" Content-Type, such as "multipart/mixed".- Parameters:
rawContent
- the undecoded message body bytescontentType
- the value of the Content-Type header, including parameters. The boundary parameter must be present for the body parts to be decoded successfully.- Returns:
- a
MultipartMessageBody
object for accessing the parts separately. - Throws:
java.io.IOException
- if unable to decode the multipart body for any reason
-
-